Home  >  Article  >  Web Front-end  >  Can jquery delete elements with the same id?

Can jquery delete elements with the same id?

WBOY
WBOYOriginal
2022-06-06 19:04:061744browse

jquery can delete elements with the same ID. Deletion method: 1. Use "$("[id*=id value]")" to obtain element objects with the same id value; 2. Use the remove() method to delete the obtained elements with the same id value. This method uses To remove the selected element, the syntax is "element object with the same id value.remove()".

Can jquery delete elements with the same id?

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

Can jquery delete elements with the same ID

Can jquery delete elements with the same ID

1. Get the element object

The syntax is:

$("[id*=id值]")

2. Delete the selected element

remove() method removes the selected element, including all text and child nodes .

This method will also remove the data and events of the selected element.

The syntax is;

$(selector).remove()

The example is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>123</title>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("[id*=sc]").remove();
});
});
</script>
</head>
<body>
<p id="sc">这是一个段落。</p>
<div id="sc">这是另一个段落。</div>
<i id="sc">这是一个段落。</i><br>
<button>移除所有P元素</button>
</body>
</html>

Output result:

Can jquery delete elements with the same id?

Video tutorial recommendation:jQuery video tutorial

The above is the detailed content of Can jquery delete elements with the same id?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn