jquery - Move an element one place up or down in the dom tree with javascript -
i want javascript way move element 1 place or down in dom tree within particular known parent using javascript (or jquery ok), want script know when element first or last element within parent , not moved. example, if have following ...
<div id='parent_div'> <div id='div_1'></div> <div id='div_2'></div> <div id='div_3'></div> </div>
on click of button, want pass known id (let's div_2
) , move position above it, swapping position element before (in case div_1
). ids of elements don't have change, , new position doesn't need known, @ least not unless moved again.
with jquery:
var e = $("#div_2"); // move up: e.prev().insertafter(e); // move down: e.next().insertbefore(e);
Comments
Post a Comment