Reputation: 13456
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
Reputation: 2321
you can also use the each function.
$('#mydiv :input').each(function(){
if($(this).val() != '100')
$(this).val(myvariable);
});
Upvotes: 0
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
Reputation: 2122
$('#mydiv input:not([value="100"])').val(myvariable);
or
$('#mydiv input').filter(function() {
return $(this).val() != 100;
}).val(myvar);
Upvotes: 1
Reputation: 237837
You need to use the attribute not equal selector.
$('#mydiv input[value!="100"]').val(myvariable);
Upvotes: 12