Reputation: 85
I want to change the place of an element in another element
So this is what i have:
<div class="post-cont">
<div class="post-thumail">
</div>
<article>
<div class="post-home">
<div class="post-info">
<div class="post-cont">
</div>
</div>
</div>
</article>
I want to change the place of the div with class post-cont
before the div of class post-thumail
like this :
<div class="post-cont">
<div class="post-cont">
</div>
<div class="post-thumail">
</div>
<article>
<div class="post-home">
<div class="post-info">
</div>
</div>
</article>
I used the before() and append() jquery proprietaries and they don't work for me
Upvotes: 1
Views: 69
Reputation: 2363
Use this code...
$('article .post-cont').insertBefore($('.post-thumail'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="post-cont">
<div class="post-thumail">
1st
</div>
<article>
<div class="post-home">
<div class="post-info">
<div class="post-cont">
2nd
</div>
</div>
</div>
</articale>
Upvotes: 1
Reputation: 82241
You can use .insertBefore()
:
$('article .post-cont').insertBefore($('.post-thumail'));
Note: you have encorrect closing tag for article
. it should be </article>
. also make sure to close main div.
Upvotes: 4