[英]Is it possible to take a JS var representing an element that has been appended to multiple places, and delete it using the var?
看到这个小提琴。 我有一个info
变量,我可以轻松地将 append 转移到 2 个地方。 但我也想轻松地从这两个地方删除它,而不需要做一些更复杂的事情,比如$("p").remove()
我知道这看起来并不复杂,但在生产中却更难。 我一直在使用info
var,所以如果有某种方式可以说info.removeInAllInstances()
或其他东西,那就太好了
我不是 JQuery 的大师,但显然 remove() 删除了某些东西的所有实例。 您可以按特定 class 过滤并删除段落。
看这个例子:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>remove demo</title>
<style>
p {
background: yellow;
margin: 6px 0;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<p>Hello</p>
how are
<p>you?</p>
<button>Call remove() on paragraphs</button>
<script>
$( "button" ).click(function() {
$( "p" ).remove();
});
</script>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.