tags:

views:

30

answers:

2

my checkboxs each look like this:

<input id="bulk_selected_" name="bulk_selected[]" type="checkbox" value="159">
+1  A: 

Use an attribute-equals selector and .is(), like this:

return $("input[name='bulk_selected[]']").is(":checked");
//or...
return $("input[name='bulk_selected[]']:checked").length;

.is() will return true is any of the elements match the selector. Or a bit faster version:

return $("input[name='bulk_selected[]']").filter(function() { 
  return this.checked; 
}).length > 0;
Nick Craver
+1  A: 
return jQuery('[name="bulk_selected[]"]:checked').size()

If none are checked, then it will return 0 (a false value) otherwise it will return a positive number (which will be true).

David Dorward
2 things here...you should provide an element selector when using an attribute one to narrow it down some, also `.size()` is just a wrapper for `.length`....not sure why they added it really :)
Nick Craver
For any other attribute selector that's true, but "name" selectors are special and short cut to document.getElementsByName() which is far more specific than document.getElementsByTagName().See here for more info http://github.com/jeresig/sizzle/blob/master/sizzle.js#L293
sighohwell