开发者

Access wrapping element with `wrap()`

开发者 https://www.devze.com 2023-03-30 06:49 出处:网络
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:

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

精彩评论

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