King Kong
King Kong

Reputation: 2915

deleting parent which deleting child jquery

I want to delete only the parent div and keep their children as it is :

      <div id="main">
        <div id="1"></div>
        <div id="2"></div>
      </div>

How we can delete only the #main div without deleting its children div #1 & #2?. I tried detach() but it didn't work.

Upvotes: 0

Views: 63

Answers (3)

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114347

Replace the element with its contents.

$('#main').replaceWith($(this).html())

Upvotes: 1

j08691
j08691

Reputation: 207861

Try unwrap().

​$('#main div')​.unwrap();​​​​​​​​​​

jsFiddle example.

Upvotes: 6

Oliver
Oliver

Reputation: 2864

Maybe unwrap is what you want?

Upvotes: 3

Related Questions