3

I have an html input text like this :

<input type="text" name="address[5][firstname]">

i want to check if the value is exist only by input which contain a specific string like firstname. Here's what i've done so far:

if($( "input[name*='[firstname]']" ).length < 1){
   console.log('in');
}

if($( "input[name*='[firstname]']" ).length < 1){
   console.log('in');
}
1
  • 1
    Could you be specific? What do you want to do? Also, observe your console for any errors. Commented Feb 20, 2017 at 9:16

1 Answer 1

3

i want to check if the value is exist only by input which contain a specific string like firstname

Your selector is good but your if condition is wrong. You are checking < 1 but there is already an element matched and length is 1, hence the condition not satisfied. Change it to > 0

if($( "input[name*='[firstname]']" ).length > 0){
  alert('in');
}

https://jsfiddle.net/sureshatta/tuwdzgue/

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.