我有一点像这样的HTML:
<a href="#somthing" id="a1"><img src="something" /></a>
<a href="#somthing" id="a2"><img src="something" /></a>
Run Code Online (Sandbox Code Playgroud)
我需要剥离链接,所以我只剩下几个图像标签.使用jQuery执行此操作的最有效方法是什么?
$("a > img").parent() // match all <a><img></a>, select <a> parents
.each( function() // for each link
{
$(this).replaceWith( // replace the <a>
$(this).children().remove() ); // with its detached children.
});
Run Code Online (Sandbox Code Playgroud)