开发者

How can I move all divs before an element to after it?

开发者 https://www.devze.com 2023-04-03 12:40 出处:网络
I have a div that I\'ve selected in jQuery and it has div\'s preceding it. I want to select all of them, copy them to AFTER the开发者_StackOverflow中文版 selected div and delete them from their origin

I have a div that I've selected in jQuery and it has div's preceding it. I want to select all of them, copy them to AFTER the开发者_StackOverflow中文版 selected div and delete them from their original location.


var selected = $('#selected');
selected
    .prevAll()
    .insertAfter(selected);


Would it not be easier to move the selected div to the front of the others?

$('#selected_div').insertBefore($('#selected_div').siblings('div:first'));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号