JavaScript BOM Document Object

BOM - Document Object :

document :

The HTML web page that gets loaded on the browser is represented using the 'document' object of BOM model.

This object considers the web page as a tree which is referred to as Document Object Model ( DOM ). Each node of this tree represents HTML elements in the page as 'element' object and its attributes as properties of the 'element' object.

W3C provides DOM API consisting of properties and methods that help in traversal and manipulation of HTML page.

Shown below is the HTML web page and it's corresponding DOM structure that can be accessed using DOM API methods and properties:

dom html code
dom structure

Let us now explore some methods and properties that allow us to traverse the DOM tree and manipulate content or style for the specified node representing the HTML element.

Methods :

To access an element in HTML page we can use following methods on 'document' object from DOM API:

Method Description Example
getElementById(x) Finds element with id ‘x’ and returns an object of type element

Paragraph 1

Paragraph 2

//Selects paragraph having id ‘p1’
getElementsByTagName(x) Find element(s) whose tagname is ‘x’ and returns NodeList, which is list of element objects

Paragraph 1

Paragraph 2

getElementsByClassName(x) Find element(s) whose class attribute‘s values is ‘x’ and returns NodeList, which is list of element objects

Paragraph 1

Paragraph 2

//Selects paragraph having class = "myClass"
querySelectorAll() Find element(s) by CSS selectors and returns NodeList, which is list of element objects.

Paragraph 1

Objects :

In addition to a few methods we just learned, we can also use below-mentioned properties of 'document' object, to access HTML element.

JS DOM property

Properties :

To manipulate the content of HTML page we can use the following properties of 'element' object, given by DOM API:

js bom property and description

To manipulate the style of an HTML element we can use the following property of 'element' object given by DOM API:

js DOM API property and description
#document_object_in_javascript #Document_Object_javascript #window_object_in_javascript #dom_js #check_if_object_is_empty_javascript #javascript_copy_object #document_object_model_in_javascript #javascript_check_if_object_is_empty #javascript_object_model

(New page will open, for Comment)

Not yet commented...