除了内部元素之外,有什么方法可以删除元素: 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 至 div class="gallery" img sr
<div class="gallery"> <a href="images/rep.png" title="rep"> <img src="http://example.comhttp://img.558idc.com/uploadfile/rep.png" class="thumbnail" alt="rep" title="rep"> </a> </div>
至
<div class="gallery"> <img src="http://example.comhttp://img.558idc.com/uploadfile/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/