0

Im trying to refer to all inputs with nill value. Tried with below code and failed. I was trying to change its css thats wy used .css

$("('input').val()=''").css('border','1px solid red');

1 Answer 1

1

It's not valid to put JS function calls inside a string for use as a selector.

What you can do is select all inputs and then use the .filter() method to reduce the set to only those with a blank value:

$('input').filter(function() {
  return this.value === '';
}).css('border','1px solid red');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input value="Pineapple"> <input value=""> <input value="Orange">
<input value=""> <input value="Mango"> <input value="Lime">

You may want to use return $.trim(this.value) === '' if fields with space characters in them count as empty for your purposes.

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

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.