html - move down of values of textarea using jquery -
i have 'n' number of divs. if click add together button created new div lastly , values move next div, time first div empty. how perform 1 using jquery?
<div> <div id='mydiv1'><textarea id='mytask1'>hai</textarea></div> <div id='mydiv2'><textarea id='mytask2'>hai1</textarea></div> .................. ........................ <div id='mydiv8'><textarea id='mytask8'>hai2</textarea></div> <div id='mydiv9'><textarea id='mytask9'>hello</textarea></div> </div>
i have alter div to
<div> <div id='mydiv1'><textarea id='mytask1'></textarea></div> <div id='mydiv2'><textarea id='mytask2'>hai</textarea></div> <div id='mydiv3'><textarea id='mytask3'>hai1</textarea></div> .................. ........................ <div id='mydiv9'><textarea id='mytask9'>hai2</textarea></div> <div id='mydiv10'><textarea id='mytask10'>hello</textarea></div> </div>
i think insertbefore() improve approach:
i = i+1; //maintain counter properly. $("<div id='mydiv"+i+"'><textarea id='mytask"+i+"'></textarea></div>").insertbefore( "<div id='mydiv"+(i-1)+"'><textarea id='mytask"+(i-1)+"'></textarea></div>" );
so sequence like:
mydiv9 mydiv8 mydiv7 . . mydiv1
edit:
if ids not in right order, can go prepend():
$("#parentdiv").prepend($("<div id='"+div_id+"'><textarea id='"+task_id+"'></textarea></div>"))
a jsfiddle
hope helps.
jquery html textarea
No comments:
Post a Comment