In this article, I’m going to teach the DOM methods.

Accessing HTML elements via class

For example, you have a paragraph(p) tag and want to access it by its class name.

HTML paragraph tag

we have p tag with para class name now I want to add changes to it or access it in my JS file.

accessing element by class name

As I mentioned yesterday that whole the page in a browser is called a document. Through a document that has all the HTML elements inside itself, we can gain access to them through the DOM methods.

If you have multiple elements that have the same class in this case para we can access all of them as an array via getElementsByClassName(className).

Accessing HTML elements via tag name

if you want to access all p tag elements like array use getElementsByTagName(tagName).

Accessing HTML elements via ID

Accessing HTML elements via query selector

accessing HTML elements via querySelector

if you want to access all HTML elements have same tag,class or id we can use document.querySelectorAll(id,class or tag)

querySelectorAll

For more info refer to W3Schools or MDN

if you have any criticism, question or any difficulty let me know in the comment section below.

I am a web developer who writes web development content for you to make web development easier