Methods & Properties
Methods
In DOM, If you want to access any element in an HTML page, you have to start with accessing the document object and in Addition with Methods.
Example : if we want to select the paragraph with id⇒myParagraph then you need to select the document then you need to use the method getElementById i.e. document.getElementById("myParagraph");
So, There are many methods to select the Element of the Document.
Methods List
There are Some Other document Methods that are used to select All The Elements of Same kind.
Additional Methods
Example :
Properties
Now, As you have learnt to select the Element, you should also know about the Properties because without properties you cannot get or change the content of the selected Element.
Here, I am Using getElementById method, you can also use other method to Select the element.
Example 1:
Here,
We have used document.getElementById(id).innerHTML Property
It will select the paragraph element by its id and Outputs the Text inside the Element by innerHTML property.
Example 2:
Here,
We have used document.getElementById(id).attribute = New Text Property and src as Attribute.
It will select the img element by its id i.e. myImage and changes the src attribute of the img Element.