In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today Xiaobian to share with you how jquery delete all sub-elements in div related knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you read this article after some harvest, let's learn about it together.
Delete method: 1. Use empty(), syntax "$("div").empty();" to delete all child nodes and content;2. Use children() and remove(), syntax "$("div").children().remove();" to delete only child elements, not content.
This tutorial operates on Windows 7, jquery version 1.10.2, Dell G3 computers.
jquery deletes all child elements in div
Method 1: Use empty()
The empty() method removes all child nodes and contents of the selected element. This method does not remove the element itself, or its attributes.
The empty() method is used to "empty" descendant elements.
$(document).ready(function() { $("button").click(function() { $("div").empty(); }); }); Here are some texts.
This is a paragraph in a div block.
This is a paragraph outside the div block.
Remove content from div block
Method 2: Use children() and remove()
The remove( ) method removes an element and all its contents.
Therefore, you need to use the children() method to get all the child elements of the div element first, and then use the remove( ) method to delete the child elements obtained.
But this method does not remove the text content of the div element itself.
$(document).ready(function() { $("button").click(function() { $("div").children().remove(); }); }); Here are some texts.
This is a paragraph in a div block, child element.
This is a paragraph in a div block, child element.
This is a paragraph outside the div block.
Remove content from div block
The above is "jquery how to delete all child elements in div" all the content of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.