How jquery removes element content
This article mainly explains "jquery how to remove element content", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "jquery how to remove element content" bar!
Methods: 1, the use of children () and remove () methods to delete the contents of the specified element, the syntax is "$(element). Children (). Remove ();"; 2, the use of empty () method to delete the content of the specified element, the syntax is "$(element). Empty ();".
The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.
How does jquery remove element content
In jquery, you can set the id attribute to part of the content tag within the tag, and get part of the content object through this id.
To delete elements and content, you can generally use the following two jQuery methods:
Remove ()-deletes the selected element (and its child elements)
Empty ()-removes child elements from the selected element
Let's take a look at the use of these two methods through examples, as follows:
1. Use the children () method to return all the direct child elements of the selected element, and then delete the selected element and its child elements by the jQuery remove () method.
$(document) .ready (function () {$("button") .click (function () {$("# div1"). Children (). Remove ();}))
This is some text in the div.
This is a paragraph in the div.
This is another paragraph in the div.
Delete div element
Output result:
2. The jQuery empty () method deletes the children of the selected element.
$(document) .ready (function () {$("button") .click (function () {$("# div1"). Empty ();}); This is some text in the div.
This is a paragraph in the div.
This is another paragraph in the div.
Clear the div element
Output result:
Thank you for your reading, the above is the content of "jquery how to remove element content". After the study of this article, I believe you have a deeper understanding of how jquery removes element content, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!