DOM in JavaScript:

 DOM stands for Document Object Model. It is an Application Programming Interface that facilitates the logical layout of content and allows us to create or modify a document. In simple words, one can create/modify/delete contents using DOM.

In the HTML document, DOM views it as a tree of different nodes, where each node is one particular HTML element.

Note: DOM is not a programming language. It is a way to access or modify data.

 

  • How does DOM work?

When a browser reads the HTML document, it creates a representational tree with the nodes along with ways/methods to access different nodes in the tree.

Example of the representational tree:



  • There are majorly four elements in DOM: Documents, elements, text, attributes.
  • DOM provides functions in order to access various DOM elements in the tree. Some commonly used ones are:
    • getElementById(): Access the first element with the specified id.
    • getElementByName(): Accesses all the elements with the specified name
    • getElementByTagName():Accesses all elements with the specified Tag name
    • querySelector(): You can use this method to find elements with one or more CSS selectors.

Comments

Popular posts from this blog

Day 9: CSS - Font Formate

else-if condition in if-else statements: Concatenation in JavaScript :

Day 27: Css Variable