4

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

4 Answers 4

12

You need to use the attribute not equal selector.

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

jsFiddle

Sign up to request clarification or add additional context in comments.

1 Comment

+1 from me :-) Also here's the jquery docs with some more info: api.jquery.com/category/selectors/attribute-selectors
1
$('#mydiv input:not([value="100"])').val(myvariable);

or

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

Comments

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

alert(n);

check this link too

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

Comments

0

you can also use the each function.

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.