开发者

jQuery - exclude inputs with certain value from selector

开发者 https://www.devze.com 2023-02-25 11:09 出处:网络
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

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

精彩评论

暂无评论...
验证码 换一张
取 消