What are JavaScript DOM methods?

When a Web page (HTML) file is loaded, the browser creates a Document Object Model of the interface. As shown below:

With this object, JavaScript has enough power to change HTML as follows:

  1. Change all HTML elements
  2. Change all HTML attributes
  3. Change all CSS styles
  4. React to events on the interface

Some basic concepts in the DOM

node

Element nodes: text node attribute nodes such as ,

,

    How do I get element nodes?

    1. The getElementByID method

    Because the ID is unique, the object corresponding to the element node is returned directly

    2. The getElementByTagName method

    Tags are used to find nodes, and since more than one element may use the Tag, an array of objects is returned

    3. GetElementByClassName method

    Returns an array of objects

    How do I get and set properties?

    1. getAttribute

    2. setAttribute