Introduction To DOM
DOM refers to the Document Object Modal. Every time Browser Loads Any Webpage it creates the DOM of that Page.
Or You can simply understand that when any page is loaded in the browser it generates a structure of the website, which element comes under which Element.
You can Understand this by looking to The Flowchart:
What you can do with DOM?
- You can add new HTML elements and attributes
- You can change all the HTML elements and attributes in the page
- You can change all the CSS styles in the page
- You can remove existing HTML elements and attributes
- You can create new HTML events in the page
DOM Methods & Properties
DOM Methods and Properties are used to perform actions in DOM.
- DOM methods are actions you can perform (on HTML Elements like adding or removing an HTML Element).
- getElementById("//Id") ⇒ The Best way to select an HTML element is to use the id of the element with this Method.
- DOM properties are values (of HTML Elements) that you can set or change.
innerHTML ⇒ It is used to get and replace the content of an element.
And in the current page we are using DOM Method getElementById("myParagraph") i.e. We are Selecting the Element with Id ⇒ myParagraph
innerHTML is the DOM Property that means everything that is written inside the Selected Element
i.e. Here We have Selected the Element with Id ⇒ myParagraph and we are getting the Text written inside the Element.