I\'m not sure why jquery selector value not work, Trying to change the value of inputs to \"a\" but the length not increment, please c
If you are changing value dynamically it wouldn't get selected by attribute selector. You can use filter() instead.
Attribute selector will not check the dom node's value property it only targets the element's attribute
$('body').on('input', '.example', function() {
$('#result').text($('.example').filter(function() {
return this.value == 'a'
}).length);
});
Or you need to manually update the element attribute on input event
$('body').on('input', '.example', function() {
$(this).attr('value', this.value);
$('#result').text($('.example[value="a"]').length);
});