name
field works well. It provides a reference to the elements
.
parent.children
- Will list all elements with a name field of the parent.
parent.elements
- Will list only form elements
such as input-text, text-area, etc
var form = document.getElementById('form-1');_x000D_
console.log(form.children.firstname)_x000D_
console.log(form.elements.firstname)_x000D_
console.log(form.elements.progressBar); // undefined_x000D_
console.log(form.children.progressBar);_x000D_
console.log(form.elements.submit); // undefined
_x000D_
<form id="form-1">_x000D_
<input type="text" name="firstname" />_x000D_
<input type="file" name="file" />_x000D_
<progress name="progressBar" value="20" min="0" max="100" />_x000D_
<textarea name="address"></textarea>_x000D_
<input type="submit" name="submit" />_x000D_
</form>
_x000D_
Note: For .elements
to work, the parent
needs to be a <form> tag
. Whereas, .children
will work on any HTML-element
- such as <div>, <span>, etc
.
Good Luck...