0
<input type="number" value="88" name="fee[]" style="width:60px">
<input type="number" value="60" name="fee[]" style="width:60px">
<input type="number" value="20" name="fee[]" style="width:60px">
<input type="number" value="90" name="fee[]" style="width:60px">

i want to get index of name array in jquery which look like below

0 1 2 3 4

my script

$('input[name="fee[]"]').each(function() {          
    alert($(this).index()); //result undefine
});

2 Answers 2

1

Do you mean like this?

$('input[name="fee[]"]').each(function(index) {          
    alert(index);
});

If not, please explain further.

Note the index parameter in the function, this variable will hold the iteration value.

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

Comments

1

Your expected result is wrong, you got 4 elements so 0 1 2 3.

So if I understood your question correctly, this is what you want

 $("input[name='fee[]']").each(function(i, v) {
        alert(i);
 });

The first arg to the each function is the index and the second is the element in the current iteration.

http://api.jquery.com/jquery.each/

1 Comment

I am so sorry for my bad question actually my english is very bad. but your answer worked for me.

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.