DOM stands for Document Object Model. It is a standard to access and share document or website over the Internet. It represents how a particular document is structured and it also helps to modify the website.
-
By ID
The
getElementById()method returns an element with a specified value.
document.getElementById("heading");-
By Tag Name
The
getElementByTagName()method returns a collection of all elements with a specified tag name.
documnet.getElementsByTagName("h1");-
By Class Name
The
getElementByClassName()method returns a collection of elements with a specified class names.
document.getElementByClassName("text");-
By CSS Selectors
The
querySelector()method returns the first element that matches a CSS selector.The
querySelectorAll()method returns all matches.
document.querySelectorAll("h2.text");It represents an HTML element like
P,DIV,A,TABLE, or any other HTML element.
-
classListReturns the class names of an element.
-
idReturns the value of the id attribute of an element.
-
innerHTMLReturns the content of an element.
-
addEventListener()Attaches an event handler to an element.
-
getBoundingClientRect()Returns the size of an elements and its position relative to the viewport.
-
hasAttribute()Returns true, if an element has a given attribute.
-
removeAttribute()Removes an element from the DOM.
-
createElement()The
createElement()method creates an element node. -
appendChild()The
appendChild()method appends a node (element) as the last child of an element.
-
firstElementChildThe
firstElementChildproperty returns the first child element of the specified element. -
lastElementChildThe
lastElementChildproperty returns the last child element of an element. -
previousElementSiblingThe
previousElementSiblingproperty returns the previous element in the same tree levell. -
nextElementSiblingThe
nextElementSiblingproperty returns the next element in the same tree level.
-
remove()The
remove()method removes an element (or node) from the document.