0% found this document useful (0 votes)
2 views3 pages

javascript3-1

The HTML DOM is a standard object model that defines HTML elements as objects, their properties, methods, and events, allowing for dynamic manipulation of web pages using JavaScript. It enables developers to access, change, add, or delete HTML elements through a tree structure of objects. Key methods include getElementById for accessing elements and innerHTML for manipulating content.

Uploaded by

bijeshsharma2016
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

javascript3-1

The HTML DOM is a standard object model that defines HTML elements as objects, their properties, methods, and events, allowing for dynamic manipulation of web pages using JavaScript. It enables developers to access, change, add, or delete HTML elements through a tree structure of objects. Key methods include getElementById for accessing elements and innerHTML for manipulating content.

Uploaded by

bijeshsharma2016
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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
In other words: The HTML DOM is a standard for how to get, change, add, or
delete HTML elements.

When a web page is loaded, the browser creates a Document Object Model of
the page.
The HTML DOM model is constructed as a tree of Objects:

The HTML DOM Tree of Objects

With the object model, JavaScript gets all the power it needs to create dynamic
HTML:
 JavaScript can change all the HTML elements in the page
 JavaScript can change all the HTML attributes in the page
 JavaScript can change all the CSS styles in the page
 JavaScript can remove existing HTML elements and attributes
 JavaScript can add new HTML elements and attributes
 JavaScript can react to all existing HTML events in the page
 JavaScript can create new HTML events in the page

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).

Example:
<html>
<body>
<h2>My First Page</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"Hello World!";
</script>
</body>
</html>

The getElementById Method


The most common way to access an HTML element is to use the id of the
element.
In the example above the getElementById method used id="demo" to find the
element.

The innerHTML Property


The easiest way to get the content of an element is by using
the innerHTML property.
The innerHTML property is useful for getting or replacing the content of HTML
elements.

The HTML DOM Document Object


The document object represents your web page.
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.

Finding HTML Elements


Method Description

document.getElementById(id) Find an element by element id

document.getElementsByTagName(name) Find elements by tag name

document.getElementsByClassName(name) Find elements by class name

Changing HTML Elements


Method Description

element.innerHTML = new html content Change the inner HTML of an element

element.attribute = new value Change the attribute value of an HTML


element

element.setAttribute(attribute, value) Change the attribute value of an HTML


element

element.style.property = new style Change the style of an HTML element

document.write(text) Write into the HTML output stream

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy