HTML DOM Properties and Methods (Cont.)


The innerHTML Property
The easiest way to get or modify the content of an element is by using the innerHTML property. innerHTML is not a part of the W3C DOM specification. However, it is supported by all major browsers. The innerHTML property is useful for returning or replacing the content of HTML elements.

The innerHTML property can also be used to view the source of a page that has been dynamically modified. The code on the right gets the innerHTML (text) from the <p> element with id="intro":



   


The childNodes and nodeValue Properties
The properties childNodes and nodeValue can also be used to get the content of an element. In the example below, getElementById is a method, while childNodes and nodeValue are properties.

The code on the right gets the value of the <p> element with id="intro":



   


Demonstration
The following demonstration shows how the script of HTML and JavaScript is displayed on the Web.

     





      Eighty percent of married men cheat in America.    
      The rest cheat in Europe.    
      — Jackie Mason