Some of the Simplest Ways of Understanding how JavaScript — HTML DOM Methods Work

A normal website has a window, document, HTML, head, and body. Within the head, we have the meta, title, and script. On the other hand, the body has the div, p(paragraph), image, and h1. That being said, we can define HTML DOM methods as actions that can be performed on any HTML elements. At the same time, HTML DOM properties are defined as values of any HTML elements that can easily be changed or edited.

All HTML DOM can be accessed with JavaScript and also with other programming languages. Therefore, all HTML in DOM are called objects. While the programming interface is called the methods and properties of every objects in HTML. A property is a value that can easily be changed and a method is an action like deleting or adding an HTML element.

The document object represents the web page. Therefore, in order to access any element in an HTML page, you will need to start accessing the document object first using the method document.write

Additionally, one can add events handlers in the methods. For example, document.getElementById(id).onclick = function(){code}. This method is used to add event handler code to an onclick event.

Examples of the methods used are

  • getElementById this method is used to access an HTML element using the id of the element.
  • innerHTML method is used to get or replace content of an HTMLelement.
  • document. anchors is used to return all <a> elements that have a name attribute
  • document.body is used to return <body> element ian HTML
  • document.URL is used to return the complete URL of the HTML document
  • document. appendChild(element) is used to add an HTML element
  • style is used to change the style of an HTML element

Therefore, by using some of these methods above, you are able to find and access HTML elements in an HTML web page with ease.


One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.