Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 238
eidylon Avatar asked Aug 09 '26 04:08

eidylon


1 Answers

$('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.

like image 148
Greg Avatar answered Aug 11 '26 19:08

Greg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!