开发者

Help understanding JQuery Attribute Equals Selector

I want to find a <td role="foo" class="one two three four"> within a <div id="myid">

These two selectors work:

$('#myid td[role=foo]')

$('#myid 开发者_JAVA百科.two')

But this one doesn't, why?

$('#myid .two td[role=foo]')


Because a space in a selector string is a descendant-selector.

You would need to do:

$('#myid td.two[role=foo]')

The way you had it, you were searching for <td role="foo"> elements that are a descendant of .two.


Because your selector:

$('#myid .two td[role=foo]')

is looking for a td[role=foo] within an element of class .two within an element of id #myid.

You're using descendant selectors, rather than looking for td[role=foo].two which, I think, is what you want.


You want:

$("#myid td[role=foo].two")...

This selector:

$('#myid .two td[role=foo]')

means: find the element with ID "myid". From it find all descendants with a class of "two". From those elements find all descendants <td> elements that have a role attribute with a value of "foo".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜