I'd like to be able to do that kind of selection:
$('input[value between 6 and 11]');
Which would give me the 9 and 10. Is there a way to do that ?
You can do this with .filter()
like this:
$("input").filter(function() {
return $(this).val() >= 6 && $(this).val() <= 11;
}).somethingHere();
If you need to use this often, you could make it a selector as well:
jQuery.expr[':'].between = function(a, b, c) {
var args = c[3].split(',');
var val = parseInt(jQuery(a).val());
return val >= parseInt(args[0]) && val <= parseInt(args[1]);
};
Then you can select by:
$("input:between(6, 11)")
Just change the >=
and <=
if you don't want the range to be inclusive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With