views:

144

answers:

1

I'm seeing an error I can't replicate from a small subset of users. Here's the code:

var selected = $('#mytable input:checked');
if (selected.length == 0) {
    $('body').trigger('notice', 'Please select some items first');
    return;
}

Even when the user checks several checkboxes, the "notice" triggers. It seems selected.length is zero when it shouldn't be.


[UPDATE] The selector works when it's updated to:

var selected = $('input[class="selection"]:checked');

It seems including the id in the selector breaks things, only on IE.


This code is working for the vast majority of users and we can't replicate the issue, but for users that see the issue it's consistent and happens every time.

It seems to be isolated to IE (although I can't be sure). We're using jQuery 1.3.2 (from google CDN).

Any ideas?

+2  A: 

It would be a good idea to paste your surrounding code/event handler(s). For a starting point, I would suggest using the :checkbox selector in your first line:

$('#mytable input:checkbox:checked')

The manual says:

$(':checkbox') is equivalent to $('*:checkbox'), so $('input:checkbox') should be used instead.

Of course, that might not make any difference whatsoever. :checkbox is equivalent to $('[type=checkbox]'), so it might be that IE is choking on the input:checked part of your selector which is testing all input elements for the checked state.

karim79