Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could I select all inputs with value greater than 0?

I have a bunch of text inputs with numeric values:

<input type='text' value='25' />
<input type='text' value='0' />
<input type='text' value='45' />
<input type='text' value='-2' />
.
. etc...

I need to select only those inputs with values greater than 0. How can I do that using jQuery?

like image 388
Dimskiy Avatar asked Apr 18 '11 19:04

Dimskiy


2 Answers

Something like this, using .filter():

$('input[type="text"]').filter(function() {
    return parseInt($(this).val(), 10) > 0;
});
like image 68
BoltClock Avatar answered Nov 18 '22 02:11

BoltClock


//select all text type inputs
$('input[type=text]').each(function(){
    var val = parseInt($(this).val());
    if(val > 0)
        //your logic here
});
like image 4
pixelbobby Avatar answered Nov 18 '22 00:11

pixelbobby