0
What is the use of name attribute and why it doesn't work in my code below 👇 👇👇
HTML: <form name="form"><input type="text"/></form> <table name="table"><tr><td></td></tr></table> <button name="button" >check</button> JAVASCRIPT: console.log(document.form); console.log(document.table); console.log(document.button); //in case of form result is ok .but rest of two aren't returned
1 Respuesta
+ 3
To access elements by name attribute you can use document.getElementsByName("nameOfElem"), you will get node list of every element with this name, something like array but not exacly array, so you need to convert it to array before doing many things, easiest is to use spread
const elem = [...document.getElementsByName("any")]
More about it https://www.javascripttutorial.net/javascript-dom/javascript-getelementsbyname/