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

20th Jun 2022, 11:42 AM
RD:programmer
RD:programmer - avatar
1 Answer
+ 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/
20th Jun 2022, 12:26 PM
PanicS
PanicS - avatar