Jquery reorder delimiters
I have 3 divs who want to cancel the order on the finished order
<div id="block-1">First</div> <div id="block-2">Second</div> <div id="block-3">Third</div> How to do this in jquery?
+8
Leblaireau
source share4 answers
<div id="parent"> <div id="block-1">First</div> <div id="block-2">Second</div> <div id="block-3">Third</div> </div> And try this in jQuery
$('#parent > div').each(function() { $(this).prependTo(this.parentNode); }); You can see an example in jsfiddle http://jsfiddle.net/N7PGW/
+19
Chuck norris
source shareJust use
$('#block-2').insertBefore('#block-1'); $('#block-3').insertBefore('#block-2'); Sample script: http://jsfiddle.net/2DUXF/
+10
fcalderan
source shareThis will cancel all divs inside the div with id "div1"
$(function(){ var items=$("#div1 div").toArray(); items.reverse(); $.each(items,function(){ $("#div1").append(this); }); }); Here is jsFiddle http://jsfiddle.net/bCAVz/8/
+3
Shyju
source share $( $("div[id|=block]") .slice(1) .get() .reverse() ) .insertBefore("div[id|=block]:first"); Also note that you can add inverse array syntax to the jQuery function syntax, which will save you a selector.
0
Explosion pills
source share