[英]How to change the place of an element in another element by javascript or jQuery?
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
我想在class
post-thumail
的div之前更改class post-cont
的div的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 我使用了before()和append()jQuery专有函数,它们对我不起作用
You can use .insertBefore()
: 您可以使用
.insertBefore()
:
$('article .post-cont').insertBefore($('.post-thumail'));
Note: you have encorrect closing tag for article
. 注意:您已encorrect关闭标签的
article
。 it should be </article>
. 应该是
</article>
。 also make sure to close main div. 还请确保关闭主div。
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.