I'm trying to specify name=""
when using document.createElement
but isn't working.
Here is the code =>
var element = document.createElement("p");
element.className = "hello-there";
element.innerText = "It works";
element.name = "hello-there-name";
document.getElementById("main").appendChild(element);
console.log(document.querySelector("p").getAttribute("name"));
<div id="main"></div>
How can I fix that without using id
? Thanks
` elements don't have a name. Form elements do.
– VLAZ Oct 31 '22 at 22:02