Create a Dialog Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Dialog

Introduction

You can create a <dialog> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">create a DIALOG element with some text</button>

<script>
function myFunction() {//from   ww  w  .  j av  a  2s.  c  om
    var x = document.createElement("DIALOG");
    var t = document.createTextNode("This is an open dialog window");
    x.setAttribute("open", "open");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials