value attribute describes the default value, not the current value. You cannot use an attribute selector to solve this problem because you want to deal with current values.
Instead, you need to get all your inputs and check your current values ββone by one.
You can use the filter method to do this.
$('body').on('input', '.example', function() { $('#result').text( $('.example').filter(function (index, element) { return ( element.value === "a" ); }).length ); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" class="example" value="a"> <input type="text" class="example" value="b"> <input type="text" class="example" value="c"> <div id='result'></div>
source share