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()
精彩评论