html
<input id="1" name="myText" type="text" value="20"/>
<input id="2" name="myText" type="text" value="30"/>
<input id="3" name="myText" type="text" value="40"/>
How can I get id value by index using name?
The following code snippet is not working
var getVal = $('[name="myText"]').index(1);
jQuery holds the DOM elements in the set like an array so you can use the indexes operator(
[]) to get the element, or get the jQuery object that wraps the desired element with:eq(n)`.eq(n)`You should mention what to you consider to be
index(1)the first or the second:Or: