在jQuery中删除链接

def*_*rex 5 javascript jquery

我有一点像这样的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执行此操作的最有效方法是什么?

Sho*_*og9 8

$("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)