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

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -