gpt4 book ai didi

jquery 将当前元素包含在新的父容器中

转载 作者:行者123 更新时间:2023-12-03 23:01:55 26 4
gpt4 key购买 nike

我想在当前元素周围使用 jquery 封装一个新的父容器,类似的东西,但我不喜欢以下几行,我认为它们并不是真正正确或最佳实践:

this.before('<div id="container">');
this.after('</div>');
// do something with the new parent here
$("#container")...

有更自然的方法吗?谢谢。

最佳答案

您想使用为此构建的换行函数!

this.wrap('<div id="container"></div>');

http://api.jquery.com/wrap/

关于jquery 将当前元素包含在新的父容器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6518873/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com