开发者

Select element after .wrap()

Helo I use this code:

cur = $('input:radio');
cur.wrap('<span class="customRadio"></span>');

what i must to do to acces the '.customRadio' element? I already tried:

cur.parent('.customRadio')

and

开发者_开发问答$('.customRadio')


it works fine for me http://jsfiddle.net/QD35Z/

<div id="mah">hello</div>

var $parent = $('#mah').wrap('<span id="test"></span>').parent();
alert($parent.attr("id"));


wrapper = $('<span class="customRadio"></span>')

Then wrapper is a span element and you can use it in jQuery:

cur.wrap(wrapper)

And you have access to the wrapper:

EDIT: Sorry, you can only access the wrapper before you wrap it around your target element. The actual element wrapped around the target is not the one you have access to.

// Effects the span that will be wrapped:
wrapper.css('color', 'red')
cur.wrap(wrapper)
// Doesn't effect the span that was wrapped:
wrapper.css('border', '1px solid green')


And by using closest?

var custom = cur.closest(".customRadio");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜