The Innerhtml Property
The Innerhtml Property
The Document Object Model DOM is an API that allows programs to interact with HTML or
XML documents
The primary function of the Document Object Model is to view, access, and change the structure
of an HTML document separate from the content contained within it.
The DOM will provide you with methods and properties to retrieve, modify, update, and delete
parts of the document you are working on. The properties of the Document Object Model are
used to describe the web page or document and the methods of the Document Object Model are
used for working with parts of the web page.
A property is a value that you can get or set (like changing the content of an HTML element).
The innerHTML property is useful for getting or replacing the content of HTML elements.
The innerHTML property can be used to get or change any HTML element, including <html>
and <body>.
The getElementById Method
The most common way to access an HTML element is to use the id of the element.
For example,
<html>
<head>
<title>Sample Document</title>
</head>
<body>
<h1>An HTML Document</h1>
<p>This is a <i>simple</i> document.
</body>
</html>
1) Finding HTML Elements by Id
<html>
<body>
<a name="Rahul">Rahul</a><br>
<a name="Gautam">Gautam</a><br>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
</script>
</body>
</html>
OUTPUT
Sahil
Rahul
Gautam
<html>
<body>
<img src="pic_htmltree.gif">
<img src="pic_navigate.gif">
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
</script>
</body>
</html>
OUTPUT