phdphd Posted March 31, 2019 Share Posted March 31, 2019 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 More sharing options...
phdphd Posted March 31, 2019 Author Share Posted March 31, 2019 Actually, simply $(this).insertAfter($(this).parent().siblings(".sibling")); does the job. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.