Reputation: 629
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');
}
Upvotes: 3
Views: 411
Reputation: 121998
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/
Upvotes: 3