What’s the DOM? #2

Accessing HTML elements via class

If you want to access your HTML element and add changes to it the one approach is accessing by its class name.

HTML paragraph tag
accessing element by class name

Accessing HTML elements via tag name

Accessing HTML elements by tag name is ideal to the previous method just has a subtle difference that we change ClassName to TagName.

Accessing HTML elements via ID

If you want to access your HTML element via ID you can use getElementById(id) and getElementsById(id).

Accessing HTML elements via query selector

One of the modern and easy approaches to access every kinda HTML element such as ID,CLASS,and Tag we use document.querySelector(id or classsname or tags). This is one of the common approaches that every developer use in their day to day coding.

accessing HTML elements via querySelector
querySelectorAll

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ahmadullahnikzad

Ahmadullahnikzad

17 Followers

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