How to create a button using Javascript code

0
Hi All,   I would like to create a simple button using javascript code in html snippet. I prepared below code but it didn’t work. Could any of you please let me know what is the issue.  
asked
1 answers
1

You did everything right, works on my machine, with exactly this text, which I think is exactly what you show in your image:

var btn = document.createElement("button");
btn.innerHTML = "Click Me";
document.body.appendChild(btn);

Things to check for you: 

  • is it really failing to add the button, or is it just tucked away in a corner somewhere. In your browser open the inspector (F12) and search for “Click Me”. See if you find it;
  • is the javascript failing? In the inspector, check the console for errors;
  • is the javascript triggering at all? Add a alert as first line;
answered