How to create a button using Javascript code

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.  
1 answers

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

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;