<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<p>
) tags, we can use the following code:
$("p").empty();
$("p")
The selector selects all paragraph tags, and the empty()
method will delete the content in all paragraph tags.
<p>If you need to remove the content within the specified tag, it is also very simple. For example, we have an HTML page that contains the following content:
<div class="test"> <h1>这是一级标题</h1> <p>这是一个段落,包含一些文本。</p> </div>
<p> in the
tag.
Tag content, you can use the following code:
$(".test p").empty();
.test p
selects the div with the class name
test For all
p tags in the
tag, the empty()
method will remove the contents of these p
tags.
<p>In addition to the empty()
method, JQuery also provides the remove()
method, which can remove the element itself and its child elements. For example, we have the following HTML code:
<div class="test"> <h1>这是一级标题</h1> <p>这是一个段落,包含一些文本。</p> <p>这是另外一个段落。</p> </div>
div
tag and all the elements inside it, we can use the following code:
$(".test").remove();
.test
selects the div
tag with the class name test
, the remove()
method will delete the div
tag and all elements inside it.
<p>Summary:
<p>Removing tag content through JQuery is very simple. You only need to select the element and tag to be operated and call empty()
or remove()
Method is enough. Using JQuery can simplify development and improve efficiency. It is one of the essential tools for front-end development. The above is the detailed content of How to remove the content of tags in jquery. For more information, please follow other related articles on the PHP Chinese website!