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 selected div and delete them from their original location.
Asked
Active
Viewed 145 times
2 Answers
3
var selected = $('#selected');
selected
.prevAll()
.insertAfter(selected);

Jacob
- 77,566
- 24
- 149
- 228
-
Will this delete the previous ones? – Shamoon Sep 09 '11 at 03:12
-
@Shamoon - yes. http://stackoverflow.com/questions/1279957/jquery-how-to-move-an-element-into-another-element – Adam Caviness Sep 09 '11 at 03:14
0
Would it not be easier to move the selected div to the front of the others?
$('#selected_div').insertBefore($('#selected_div').siblings('div:first'));

Blair McMillan
- 5,299
- 2
- 25
- 45