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! Quote Link to comment https://forums.phpfreaks.com/topic/308532-move-div-to-after-parent-sibling/ 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. Quote Link to comment https://forums.phpfreaks.com/topic/308532-move-div-to-after-parent-sibling/#findComment-1565749 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.