Function / selector to filter inputs by value

Is there a built-in function / selector in jQuery to filter inputs by value?

I can create a custom selector:

$.extend($.expr[":"], {
    val: function(elem, index, match) {
       return $(elem).val() == match[3];
    }
});

and use it as follows: $("input:val('Some text')").

I'm just wondering if something like that exists, or maybe there is a better way.

+5
source share
3 answers

It doesn't seem like there is a built-in solution. But for a one-time selector .filter()is an option:

$('input').filter(function() { return $(this).val() === 'Some text'; });
+4
source

You can do it:

    $('input[value=someval]')

you can also tie it

    $('input[type=radio][value=someval]')

look here :

+2
source
$.extend($.expr[":"], {
    val: function(elem, index, match) {
       return $.trim($(elem).val()) == $.trim(match[3]);
    }
});
+2
source

All Articles