views:

169

answers:

1

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?

+5  A: 

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

Greg
Good call......
bdukes
So I guess it must be something in the way jQuery checks an id(#) selector vs. the way it checks an attribute ([]) selector, yes? I was using the id attribute to identify a span in rows in a DataGrid control (bound programmatically). Instead what I did is changed it to "fieldid=" and adjusted my selector accordingly. Thanks for explaining!
eidylon