Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 .two')

But this one doesn't, why?

$('#myid .two td[role=foo]')
like image 883
Dan Avatar asked Dec 04 '22 11:12

Dan


1 Answers

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.

like image 189
user113716 Avatar answered Dec 19 '22 12:12

user113716