开发者

Selecting only the first-level elements for .delegate()

How do I only select the first level of children of an element when using .delegate()?

Say, I have the following HT开发者_运维技巧ML:

<div id="list">
  <div>Item 1<div>Item 1-1</div></div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>

When I do $('#list').delegate('div', 'click', function(e) {}), the element <div>Item 1-1</div> would be included (right?) in the handler. How do I only select the first-level child elements for #list with this method then?


You can do the following to only select direct children:

$('#list').delegate('#list > div', 'click', function(e) {});


you will got solution here i think .if my guess correct

Selecting only first level element, not child elements with the same element name

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜