I am trying to create JavaScript ARRAY and get the name of the child.
(I don't need span elements, only input, select and textarea)
HTML:
<div id="new"> ID: <input name="id" /> <span>Date: </span> <input name="date" /> <select name="status"> <option>New</option> <option>Old</option> </select> <textarea name="memo"></textarea> ... etc. </div>
Jquery
var elements=new Array(); $("#new").each(function() { elements = $(this).children('input, select, textarea').attr("name"); });
With this code, I get only one element name ("id"). When I test an array with index 0, it works. BUT, when I use a different index, say ... to warn the "date" or "status", it does not work:
alert( elements[0] ); //Output: "id" alert( elements[2] ); //Output: "undefined". It should alert "status" instead
source share