jill1993 jill1993 - 9 months ago 52
Javascript Question

How do you dynamically display a button using JavaScript?

Below I have code where I am trying to dynamically create a button using Javascript (I don't want to just create a button with HTML) When I locally run the web page no button appears.

The buttonActionFunction is a separate function I have (that is fully working) where an image appears when the button is clicked.

Also how do I add to that code so that once the button is clicked that the button deactivates so they can't click it again?

function buttonFunction() {
var button= document.createElement("button");
button.appendChild(document.createTextNode("Click Me"));

Answer Source
 function createButton(context, func) {
     var button = document.createElement("input");
     button.type = "button";
     button.value = "Click Me";
     button.onclick = func;
 function functienaam()
     createButton(document.body, functienaam);
 createButton(document.body, functienaam);

jsfiddle : https://jsfiddle.net/fv42orad/1/