HTML Dom
HTML Dom
HTML Dom
When a web page is loaded, the browser creates a Document Object Model of
the page.
<html>
<head>
<title>My Title</title>
<head>
<body>
<h1>My Header</h1>
</body>
</ html>
With the object model, JavaScript gets all the power it needs to create dynamic
HTML:
HTML DOM properties are values (of HTML Elements) that you can set or
change.
A property is a value that you can get or set (like changing the content of an
HTML element).
A method is an action you can do (like add or deleting an HTML element).
In the example above the getElementById method used id="demo" to find the
element.
The innerHTML property is useful for getting or replacing the content of HTML
elements.
If you want to access any element in an HTML page, you always start with
accessing the document object.
Below are some examples of how you can use the document object to access
and manipulate HTML.
Example:
<html>
<head>
<title>DOM!!!</title>
</head>
<body>
<h1 id="s">Welcome</h1>
<h2 class="q">Technology</h2>
<script>
var x=document.getElementById("s");
alert("first header:"+x.innerHTML);
var y=document.getElementsByClassName("q");
alert("second header:"+y.innerHTML);
var p = document.getElementsByTagName("p");
document.getElementById
</script>
</body>
</html>
Output: