javascript - Adding div before selected div -


i have bunch of divs 1 after other.

<div class="betweenable">some content</div> <div class="betweenable">other content</div> <div class="betweenable">yet another</div> 

when click last div, want insert text new content in div before it, final result be

<div class="betweenable">some content</div> <div class="betweenable">other content</div> <div class="betweenable">new content</div> <div class="betweenable">yet another</div> 

i tried append it's adding new markup inside select div at top. want inserted outside selected div , right before it. should use instead of line

var newmarkup = '<div class="betweenable">new content</div>'; $(this).prepend(); 

you can try

$('.betweenable').click(function(){    var newmarkup = '<div class="betweenable">new content</div>';    $(this).before(newmarkup); }); 

here's example : http://jsfiddle.net/jomanlk/c4xyh/


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -