开发者

Syntax for using a saved jquery selector?

I would like to use a saved selector and drill down further with it. In this case I would like to access the link tag contained in the element with the id

html

<div id='selectedElement'>
   <a h开发者_开发百科ref="#">some link</a>
</div>


var $selector = $('#selectedElement');


Just use .find()

<div id='selectedElement'>
   <a href="#">some link</a>
</div>

var $selector = $('#selectedElement'),
    $anchor = $selector.find('a');


var $selector = $('#selectedElement');

// a will contain a reference to all <a> elements that are a descendent of the
// the element with id "selectedElement"
var a = $selector.find('a');

since $selector has been assigned a jQuery object which contains references to elements in the DOM that match the selector #selectedElement, you can use the $selector variable to drill down further.


you can easily use the same way:

var selector = $('#selectedElement');

alert( selector.find("a").attr("href") );
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜