What are the document methods supported by Legacy DOM?

The Legacy DOM provided several document methods for manipulating document content. While most are deprecated in modern web development, understanding them helps with legacy code maintenance.

Legacy DOM Document Methods

Method Description & Usage
clear() Deprecated - Erased document contents and returned nothing.
Example: document.clear()
close() Closes a document stream opened with open() method.
Example: document.close()
open() Deletes existing content and opens a stream for new content.
Example: document.open()
write() Inserts strings into the document during parsing or after open().
Example: document.write("Hello World")
writeln() Same as write() but appends a newline character.
Example: document.writeln("Hello World")

Example: Using document.write()

<html>
<head>
    <title>Legacy DOM Example</title>
</head>
<body>
    <script>
        document.write("<h2>Welcome to Legacy DOM</h2>");
        document.writeln("<p>This is line 1</p>");
        document.writeln("<p>This is line 2</p>");
    </script>
</body>
</html>
Welcome to Legacy DOM
This is line 1
This is line 2

Modern Alternative

Modern JavaScript uses DOM manipulation methods instead:

<html>
<head>
    <title>Modern DOM Example</title>
</head>
<body>
    <div id="content"></div>
    <script>
        const content = document.getElementById("content");
        content.innerHTML = "<h2>Modern DOM Approach</h2><p>Better practice</p>";
    </script>
</body>
</html>

Key Points

  • document.clear() is completely deprecated and should not be used
  • document.write() can break the page if called after loading completes
  • open() and close() are mainly used with dynamically created documents
  • Modern DOM methods like innerHTML, appendChild() are preferred

Conclusion

Legacy DOM methods were essential for early web development but are largely obsolete today. Modern DOM manipulation provides better performance and maintainability for dynamic content creation.

Updated on: 2026-03-15T23:18:59+05:30

167 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements