Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove matched tags but leave content with JQuery

I have HTML like this:

<div>
 <div class="a">
  content1
 </div>
 content 2
 <div class="a">
  <b>content 3</b>
 </div>
</div>

and I want to get rid of the div's of class="a" but leave their content. My initial attempt was:

$("div.a").replaceWith($(this).html());

However this is undefined. How would you do this?

like image 252
hoju Avatar asked Dec 14 '22 00:12

hoju


1 Answers

try

$("div.a").each(function(){
    $(this).replaceWith($(this).html());
});
like image 71
Danny Roberts Avatar answered Dec 29 '22 01:12

Danny Roberts