JS HTML Dom
JS HTML Dom
1
JavaScript HTML DOM
With the HTML DOM, JavaScript can access and change all
the elements of an HTML document.
2
With the object model, JavaScript gets all the power it
needs to create dynamic HTML:
3
What is the DOM?
The DOM is a W3C (World Wide Web Consortium)
standard.
4
What is the HTML DOM?
The HTML DOM is a standard object model
and programming interface for HTML.
It defines:
•The HTML elements as objects
•The properties of all HTML elements
•The methods to access all HTML elements
•The events for all HTML elements
5
HTML DOM Methods and Properties
HTML DOM methods are actions you can perform (on HTML
Elements).
HTML DOM properties are values (of HTML Elements) that you
can set or change.
The DOM Programming Interface
The HTML DOM can be accessed with JavaScript (and with
other programming languages).
•In the DOM, all HTML elements are defined as objects.
•The programming interface is the properties and methods of
each object.
•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).
EX: <script>
document.getElementById("demo").innerHTML = "Hello
World!“;</script>
6
The HTML DOM Document
Object
The document object represents the web page.
7
Changing HTML Elements /Add/Deleting elements
Property Description
Method Description
Method Description
document.createElement(element) Create an HTML element
8
Changing HTML Content
The easiest way to modify the content of an HTML
element is by using the innerHTML property.
To change the content of an HTML element,
syntax:
document.getElementById(id).innerHTML = new HTML
This example changes the content of a <p> element:
<html><body>
<p id="p1">Hello World!</p>
<script>
document.getElementById("p1").innerHTML = "New text!";
</script></body></html>
HTML DOM Collection Object