Reputation: 2289
I have the following Jquery code:
var $others = $('input[type="checkbox"]')
But I want to exclude a checkbox where the Value is "All"
<input checked="checked" id="role_ids_" name="role_ids[]" type="checkbox" value="All" />
<input checked="checked" id="role_ids_" name="role_ids[]" type="checkbox" value="Age" />
<input checked="checked" id="role_ids_" name="role_ids[]" type="checkbox" value="field" />
<input checked="checked" id="role_ids_" name="role_ids[]" type="checkbox" value="product" />
<input checked="checked" id="role_ids_" name="role_ids[]" type="checkbox" value="officer" />
<input checked="checked" id="role_ids_" name="role_ids[]" type="checkbox" value="regional" />
Can I use something like not()
?
Upvotes: 2
Views: 246
Reputation: 1289
It can be done with the Attribute Not Equal Selector
Demo: http://jsfiddle.net/4jo3tL54
var $others = $('input[type="checkbox"][value!="All"]')
$.each($others, function( i, v ) {
console.log(v.value);
});
Upvotes: 0
Reputation: 49095
You can use the Attribute Not Equal Selector:
var $others = $('input[type="checkbox"][value!="All"]');
If you already have an initialized context, and only want to filter it, you can use not():
var $elms = $('input[type="checkbox"]');
var $others = $elms.not('[value="All"]')
Upvotes: 2
Reputation: 2569
You can use $('input[value!="All"]')
Also, do not assign same id to all checkboxes. IDs are supposed to be unique.
Upvotes: 0
Reputation: 76593
I believe
var $others = $('input[type="checkbox"]:not([value="All"])')
should work, where you use the :not
pseudo-selector
Upvotes: 0