views:

148

answers:

2

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?

+6  A: 

try

$("div.a").each(function(){
    $(this).replaceWith($(this).html());
});
Danny Roberts
+3  A: 

Replacing elements with their stringified HTML content will nuke any event handlers that might be in place. This won't:

$("div.a").each(function () {
    $(this).replaceWith($(this.childNodes));
});
Sean