开发者

Access wrapping element with `wrap()`

I'm using the jQuery开发者_高级运维 function wrap(), which returns the original object, not the wrapping object. Is there an easy way to access the wrapping object?


Use the parent[API Ref] method:

$('#myElement').wrap('<div></div>').parent();


You can give wrapping an element an id and reference it something like:

$('..........').wrap('<div id="mydiv" />');

Now you can reference the wrapper element using:

$('#mydiv')

Or you can simply use parent()


After you wrap an element actually you are assigning a parent to it.

So, use $('yourWrappedElement').parent()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜