Document createElement() Method - Create a button with text: - Javascript DOM

Javascript examples for DOM:Document createElement

Description

Document createElement() Method - Create a button with text:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//w  w w  .ja  va  2 s  .  c  o  m
    var btn = document.createElement("BUTTON");
    var t = document.createTextNode("CLICK ME");
    btn.appendChild(t);
    document.body.appendChild(btn);
}
</script>

</body>
</html>

Related Tutorials