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);
>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);
