有没有办法删除除内部元素之外的元素:
<div class="gallery">
<a href="images/rep.png" title="rep">
<img src="http://example.com/uploads/rep.png" class="thumbnail" alt="rep" title="rep">
</a>
</div>
to
<div class="gallery">
<img src="http://example.com/uploads/rep.png" class="thumbnail" alt="rep" title="rep">
</div>
我写了这段代码但不起作用:
$(".gallery").contents().filter(".thumbnail").remove();
jQuery 有一个unwrap()
删除父节点并将匹配元素保留在适当位置的方法:
$(".gallery").contents().filter(".thumbnail").unwrap();
// or (faster)
$(".gallery .thumbnail").unwrap();
- http://api.jquery.com/unwrap/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)