simPod
simPod

Reputation: 13456

jQuery - exclude inputs with certain value from selector

I would like to select all inputs in my div and set them new value but also I want to exclude inputs with certain value something like this:

$('#mydiv input:not(val("100")').val(myvariable);

how to do that, is it possible in simple selector? thanks

Upvotes: 4

Views: 4854

Answers (4)

Sai Kumar
Sai Kumar

Reputation: 2321

you can also use the each function.

$('#mydiv :input').each(function(){

    if($(this).val() != '100')
       $(this).val(myvariable);
});

Upvotes: 0

Harish
Harish

Reputation: 2324

var n = jQuery("input[value!='1']").val();

alert(n);

check this link too

http://api.jquery.com/attribute-not-equal-selector/

Upvotes: 1

Alex
Alex

Reputation: 2122

$('#mydiv input:not([value="100"])').val(myvariable);

or

$('#mydiv input').filter(function() {
    return $(this).val() != 100;
}).val(myvar);

Upvotes: 1

lonesomeday
lonesomeday

Reputation: 237837

You need to use the attribute not equal selector.

$('#mydiv input[value!="100"]').val(myvariable);

jsFiddle

Upvotes: 12

Related Questions