supernova
supernova

Reputation: 3883

jquery replace all <ol> with <ul>

Given the following dom structure I would like to transform an ordered list to an unordered list.

<div class="wrapper"> 
  <ol>
    <li><div>foo</div></li>
    <ol>
      <li><div>bar</div></li>
    </ol>
    <li><div>batz</div></li>
  </ol>
</div>

What is the best way to do this?

Upvotes: 3

Views: 5803

Answers (2)

supernova
supernova

Reputation: 3883

ok i had to work from the inside to the outside, only replaceWith wasn't working because it replaced only the outer tags and didn't replace the inner ones, so i solved it this way:

$($('.wrapper').find('ol').get().reverse()).each(function(){
  $(this).replaceWith($('<ul>'+$(this).html()+'</ul>'))
})

if someone has a better solution i would be glad to hear it.

Upvotes: 4

Anthony Simmon
Anthony Simmon

Reputation: 1607

You should use jQuery replaceWith.

Upvotes: 4

Related Questions