Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Button Name not able to set with setAttribute("name", "Button Name")

I am creating a button on my web page but I have tried various things and I either get an error or the button is not populating with any text (see screenshot below, there should be a button called "BUTTON NAME" right above the words "Keys 2". What could I be doing wrong?

dropDownButton = document.createElement("button");
dropDownButton.setAttribute("name", "BUTTON NAME")
document.body.appendChild(dropDownButton);

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s setting the name attribute, but that doesn’t affect the display at all. (You can inspect the element in your browser’s debugging tools to see the attributes.) You can also set the content of the <button> element:

dropDownButton = document.createElement("button");
dropDownButton.setAttribute("name", "BUTTON NAME");
dropDownButton.textContent = "BUTTON NAME";
document.body.appendChild(dropDownButton);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading