HomeLanguagesJavascriptHTML DOM createHTMLDocument() Method

HTML DOM createHTMLDocument() Method

The DOMImplementation createHTMLDocument() method is used to create a new HTML Document.

Syntax:

newDoc = document.implementation.createHTMLDocument(title);

Parameters:

  • title (Optional): It is a DOMString containing the title to be used for the new HTML document.

Return Value: This function returns Created HTML Document.

Example: In this example, we will create an HTML document using this method.

html




<!DOCTYPE HTML>
<html> 
<head>
    <meta charset="UTF-8">
    <title>createHTMLDocument() method</title>
</head>  
 
<body style="text-align:center;">
    <h1 style="color:green;"> 
     neveropen
    </h1>
    <p id="a">
    HTML | DOM createHTMLDocument() method
    </p>
 
    <button onclick = "Geeks()">
    Click Here
    </button>
    <script>
        function Geeks(){
            var doc =
document.implementation.createHTMLDocument("New Document");
            var p = doc.createElement("p");
            p.innerHTML = "neveropen";
            doc.body.appendChild(p);
            console.log(doc);
        }
  </script>
</body>  
</html>


Output:

Before Button Click:

After Button Click: Created document can be seen in the console.

Supported Browsers:

  • Google Chrome 1
  • Edge 12
  • Firefox 4
  • Safari 1
  • Opera 12.1
  • Internet Explorer 9
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32715 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7093 POSTS0 COMMENTS
Nicole Veronica
12231 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12315 POSTS0 COMMENTS
Shaida Kate Naidoo
7210 POSTS0 COMMENTS
Ted Musemwa
7474 POSTS0 COMMENTS
Thapelo Manthata
7195 POSTS0 COMMENTS
Umr Jansen
7173 POSTS0 COMMENTS