Reputation: 45
<input type="text" name="test[ooo][]">
<input type="text" name="test[bbb][]">
<input type="text" name="test[ccc][]">
<input type="text" name="test[vvv][]">
$('input').each(function(){
console.log($(this).attr('name').index('bbb'));
})
Why this not working? How can i check index for attribute name from input?
I don't must use index(). I can use other function, but how can i check this?
Upvotes: 1
Views: 158
Reputation: 14002
try this code:
inputs= document.getElementsByTagName("input");
for(i=0;i<inputs.length;i++)
alert(i);
Upvotes: 1
Reputation: 3186
This doesn't work because the jQuery selects all for input elements, and loop through them, interpreting the names as name-strings. In jQuery's mind this are not arrays at all.
Off course you can always select a specific input by selecting a substring in its name:
console.log( $('input[name*="[bbb]"]') );
this will select an input
with it's name containing the substring [bbb]
.
Upvotes: 1
Reputation: 102763
I think you're looking for indexOf
.
console.log($(this).attr('name').indexOf('bbb'));
-1
5
-1
-1
Upvotes: 2