JavaScript Document Object Model (DOM)

JavaScript Document Object Model (DOM)

Common Methods and Properties

What are the methods of the Document Object Model?

Bellow, we will know some of the methods of the Document Object Model.

Get Elements:

These are the common methods to get the dom elements

  • getElementById(ID)
  • getElementsByTagName(TAG)
  • getElementsByClassName(CSS CLASS)
  • querySelector(CSS QUERY)
  • querySelectorAll(CSS QUERY)

Create and Delete Elements:

These are the common methods to create and delete the dom elements

  • createElement(NAME)
  • PARENT.appendChild(NODE)
  • PARENT.removeChild(NODE)
  • PARENT.replaceChild(NEW, OLD)
  • PARENT.insertBefore(NEW NODE, OLD NODE)

Text Contents:

These are the common methods to get the text content from dom elements

  • NODE.innerHTML
  • NODE.textContent
  • NODE.value

CSS:

These are the common methods to apply CSS to the dom elements

  • NODE.className
  • NODE.classList
  • NODE.classList.add(CLASS)
  • NODE.classList.remove(CLASS)
  • NODE.classList.toggle(CLASS)

Attributes:

These are the common methods to access the attributes of the dom elements

  • NODE.hasAttribute(NAME)
  • NODE.getAttribute(NAME)
  • NODE.setAttribute(NAME, VALUE)
  • NODE.removeAttribute(NAME)

JavaScript Document Object Model (DOM)

 

Leave a Comment

Your email address will not be published. Required fields are marked *