[英]Remove element completely from div
我有一个通用类的多个svg。
<div id="holder">
<svg width="100" height="100" class="circle">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>
</div>
如何将其完全删除? 我尝试了.empty();
和remove();
但是没用吗?
$('#removeBtn').click(function(){
$('.circle').remove();
});
我猜你错过了DOM ready处理程序:)
例如
$(function(){
$('#removeBtn').click(function(){
$('.circle').remove();
});
});
$(function(){})
只是$(document).ready(function(){})
的便捷快捷方式
您的html
<div id="holder">
<svg width="100" height="100" class="circle">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>
</div>
<button id="removeBtn" >remove</button>
和js
$('#removeBtn').click(function(){
$('.circle').remove()
});
这里的小提琴
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.