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
You need to use the attribute not equal selector.
$('#mydiv input[value!="100"]').val(myvariable);
jsFiddle
$('#mydiv input:not([value="100"])').val(myvariable);
or
$('#mydiv input').filter(function() {
return $(this).val() != 100;
}).val(myvar);
var n = jQuery("input[value!='1']").val();
alert(n);
check this link too
http://api.jquery.com/attribute-not-equal-selector/
you can also use the each function.
$('#mydiv :input').each(function(){
if($(this).val() != '100')
$(this).val(myvariable);
});
精彩评论