JavaScript HTML DOM
Through the HTML DOM, access to all the elements JavaScript HTML document.
HTML DOM (Document Object Model)
When the page is loaded, the browser will create the page document object model (Document Object Model).
HTML DOM model is structured as a tree of objects:
HTML DOM tree
Programmable object model, JavaScript gained sufficient ability to create dynamic HTML.
- JavaScript can change page for all HTML elements
- JavaScript can change HTML page all properties
- JavaScript can change page all CSS styles
- JavaScript can react to all events page
Finding HTML elements
Typically, JavaScript, you need to manipulate HTML elements.
In order to do this thing, you must first find the element. There are three ways to do this:
- Find HTML elements by id
- Find HTML elements by tag name
- Find HTML elements by class name
Finding HTML elements by id
Finding HTML elements in the DOM The easiest way is by using the element's id.
This example finds id = "intro" element:
If it finds the element, the method will be the object form (x in) the returns that element.
If the element is not found, then x will contain null.
Finding HTML elements by tag name
This example finds id = "main" elements, and then look for id = "main" element in all <p> elements:
Find HTML elements by class name
In this case bygetElementsByClassName function to find the class = "intro" element:
HTML DOM Tutorial
In this tutorial the following pages, you will learn:
- How to change the content of the HTML element (innerHTML)
- How to change the style of HTML elements (CSS)
- How HTML DOM event of a reaction
- How do I add or remove HTML elements