Select inputs with number type through jQuery

49,576

Solution 1

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'); });
});

Solution 2

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

Solution 3

As you can see here your code works well... http://jsfiddle.net/U47Vj/ Maybe your Browser does not support this HTML5 Feature. In Chrome everything is fine. Same code in FF 3.6 breaks.

Solution 4

i think your problem is the ":" before input.

try:

$('input[type="number"]').click(function () { alert('hello'); }); 
Share:
49,576
Diogo Cardoso
Author by

Diogo Cardoso

JavaScript enthusiast

Updated on July 09, 2022

Comments

  • Diogo Cardoso
    Diogo Cardoso almost 2 years

    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.