How can I select all inputs with number type in jQuery?
The following code doesn't work:
$(':input[type="number"]').click(function () {
alert('hello');
});
Thanks.
Your selector is correct. Using the attribute-equals-selector
(docs), it will select input elements with that type.
You'll need to be sure the DOM is loaded before running it.
Example: http://jsfiddle.net/H2aQr/
$(function() {
$(':input[type="number"]').click(function () { alert('hello'); });
});
You don't need the colon at the beginning, that's for selecting types of input, like $('input:text')
so $('input[type="number"]').click(function () { alert('hello'); });
works just fine
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