[英]jQuery how to remove an appended A tag with a given id
我刚刚附加了一个 A 标签,我正在尝试将其删除,谢谢您的帮助。
HTML:
<div>
<p id="header"></p>
</div>
jQuery:
$(document).ready(function (e) {
// Append A tag with id= Test1
$('#header').append("<a href='#' id='Test1'> Test1</a>");
// Remove the tag - it doesn't work.
$('#header').remove("a#Test1");
}
$(document).ready(function(e) { // Append A tag with id= Test1 $('#header').append("<a href='#' id='Test1'> Test1</a>"); // Remove the tag - it doesn't work. $('#header a#Test1').remove(); })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <p id="header"></p> </div>
使用$('#header a#Test1').remove();
但您只需要$('#Test1').remove()
来删除该特定元素
您也可以通过以下方式实现:
$('#header').empty();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.