jQuery 如何在jQuery中附加兄弟姐妹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6149615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to append on sibling in jQuery?
提问by Anirudha Gupta
I have this code
我有这个代码
<div class="data">
<div class="another">
</div>
<!-- need to add element here -->
</div>
I want to add the element where I put comment using jQuery how I can append sibling of another using jQuery
我想添加使用 jQuery 放置评论的元素如何使用 jQuery 附加另一个元素的兄弟
回答by Alex R.
If you specifically want to insert after the another
div
element, try insertAfter:
如果您特别想在another
div
元素之后插入,请尝试insertAfter:
$('<div>Another 2</div>').insertAfter($('.another'));
In the $('.another')
part, you can otherwise specify the target more precisely.
在$('.another')
零件中,您可以另外更精确地指定目标。
回答by Richard Dalton
回答by metaforce
try:
尝试:
$('div#data').append('your HTML');