Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery append after into an element before

Tags:

jquery

I am trying to move content to be after test2 but at the moment it's not working.

<div id="test">
    <div id="test2"></div>  
</div>

<div id="content"></div>

I'm using the following jQuery:

$("#test2").after("#content");

This is how .after() is meant to function? I've checked the jQuery docs and can't find what I'm doing wrong?

like image 689
Dan Avatar asked Dec 17 '22 02:12

Dan


1 Answers

$("#content").insertAfter("#test2");​

will result in:

<div id="test">
    <div id="test2">b</div>
    <div id="content">a</div>  
</div>

jsFiddle example.

like image 136
j08691 Avatar answered Jan 14 '23 21:01

j08691