Jump to content

Move Div To After Parent Sibling


phdphd

Recommended Posts

Hi All,

I am trying to move a DIV with a specific class after one of its parent's sibling with a specific class too, but it does not work.

The HTML

 

    <div class="sibling">
    </div>
     <div class="hello">
          <div >
               Hello
           </div>
              
           <div class="world">
                world
           </div>
   </div>

The jQuery

$('div').each(function (){
    if($(this).hasClass("world")){
      $(this)(".world").insertAfter($(this).parent().siblings(".sibling"));
    
	}
    
  });

 

I would like that output

 

<div class="sibling">
</div>
<div class="world">
world
</div>
<div class="hello">
       <div >
            Hello
       </div>
</div>

Thanks!

 

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.