eidylon
eidylon

Reputation: 7238

jQuery Selector not working right

Okay, I cannot figure out what I'm doing wrong here...

Take the following jQuery selector...

$('tr[batchid]:has(span.chkselb input:checked) span[id=assetcount]')

This returns 2 elements. Yet if I do the following selector:

$('tr[batchid]:has(span.chkselb input:checked) span#assetcount')

This returns 0 elements. Aren't these two selectors for all intents and purposes identical?
Or is there some strange interaction with the ":has" operator or something? I got it working with the first statement, but I'm really curious why the second one (my original selector) doesn't work. Any insights?

Upvotes: 3

Views: 1032

Answers (1)

Greg
Greg

Reputation: 321578

$('tr[batchid]:has(span.chkselb input:checked) span[id=assetcount]') shouldn't return two elements, as IDs have to be unique.

This suggests to me that you're re-using IDs, and I guess the first one you use doesn't match tr[batchid]:has(span.chkselb input:checked) so the second selector doesn't return any rows.

You should make the IDs unique.

Upvotes: 6

Related Questions