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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 20:28:08  来源:igfitidea点击:

how to append on sibling in jQuery?

jqueryhtml

提问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 anotherdivelement, try insertAfter:

如果您特别想在anotherdiv元素之后插入,请尝试insertAfter

$('<div>Another 2</div>').insertAfter($('.another'));

In the $('.another')part, you can otherwise specify the target more precisely.

$('.another')零件中,您可以另外更精确地指定目标。

回答by Richard Dalton

I think you want to use the .after()function:

我想你想使用.after()函数:

$('div.another').after('<div>');

回答by metaforce

try:

尝试:

$('div#data').append('your HTML');