Open In App

How to Access Document Properties using W3C DOM ?

In this article, we’ll learn about W3C DOM document properties, their methods for manipulating documents, and how they work in practice.

The World Wide Web Consortium, or WWW has established the document object model, which enables entry to and modification of every piece of document information (W3C). The document object model (DOM) in Internet Explorer 4 was first made available by Microsoft. The majority of fundamental W3C DOM elements are supported by IE 5 and subsequent versions. The majority of current browsers accept this model.



The W3C DOM presents new features while standardizing the majority of the legacy DOM’s existing ones. It specifies methods that enable scripts to access and modify any document element, not just specialized elements such as forms and images, in addition to handling forms[], images[], as well as other array characteristics of the Document object.

W3C DOM Document Properties: All Legacy DOM attributes are supported by this model. Below is a collection of document properties that can also be viewed through the W3C DOM.



Property & Specifications:

W3C DOM Document Methods: All of the Standard DOM’s accessible methods are supported by this model. Here is a collection of additional techniques that the W3C DOM supports.

Property & Specifications:

Example 1: In this example,  we will access the document properties using W3C DOM method getElementById.




<!DOCTYPE html>
<html>
<head>
    <title> GeeksForGeeks </title>
    <script type="text/javascript">
        function Func() {
            var ret = document.getElementById("heading");
            alert(ret.innerHTML);
        }
    </script>
</head>
  
<body>
    <h1 id="heading">GeeksForGeeks</h1>
    <p>
          Example to illustrate about how to access the 
          document <br> properties using W3C DOM method 
          getElementById. 
      </p>
    <form id="form" name="formname">
        <input type="button" value="Click" onclick="Func();" />
    </form>
</body>
</html>

Output:

Accessing document properties using the W3C DOM method getElementById.

Example 2: In this example,  we will access the document properties using the W3C DOM method getElementsByTagName.




<!DOCTYPE html>
<html>
<head>
    <title> GeeksForGeeks </title>
    <script type="text/javascript">
        function Func() {
            var gfg = document.getElementsByTagName("title");
            alert("Title of the document: " + gfg[0].text);
        }
    </script>
</head>
  
<body>
    <h1 id="heading">GeeksForGeeks</h1>
    <p>    
          Example to illustrate about how to access the 
          document <br> properties using W3C DOM method 
          getElementsByTagName. 
      </p>
    <form id="form" name="formname">
        <input type="button" value="Click" onclick="Func();" />
    </form>
</body>
</html>

Output:

Accessing document properties using W3C DOM method getElementsByTagName.

The above examples return objects for the forms and elements, and we would have to use those object properties to retrieve their values.


Article Tags :