I'm reading the jquery manual regarding the .after()
function:
$('.container').after($('h2'));
and it says
"If an element selected this way is inserted elsewhere, it will be moved rather than cloned"
So if I have multiple
<div class='before' onclick='afterfunction();'><div>
,
and I would want to place <div class='after'></div>
after whichever div is clicked (have it move, not clone) would I do something like this?
var afterdiv = "<div class='after'></div>";
function afterfunction() {
$(this).after(afterdiv);
}
Thanks for all your help!
Like you said:
But you missed the bold part.
And you don't need to
.remove()
it (like wrongly suggested in an answer here.)demo jsFiddle