Using DOM Selector we can select, manipulate and edit the different types of text.
We have different DOM selectors Here the list of DOM selectors, and let’s use them one by one.
Using DOM selector (getElementsByTagName) We can get any element using tag name as I write the code above.
Using DOM selector (getElementsByClassName) We can get any element using class name as I write the code above.
Using DOM selector (getElementById) We can get any element using Id as I write the code above.
4- querySelector and querySelectorAll
Here In the above code, for querySelector, I write the code for “li” to select the “li” and in querySelectorAll I write the 2 examples in first we select all “li” elements, and the second example I show how can select more than one element.
5- getAttribute and setAttribute
< li name =”random”> First List </ li >
First I get the “random” and in second-line, I change the value of random this way we can get and set Attribute.
We can change styling using querySelector, getelementsByClassName, getElementById. We can add style like this anywhere on the page but It’s not the right way to do that the best way is that add the class.
First, we define a variable then we assign h1 or any tag to the variable just for not write the h1 tag every time. Then we can add class to h1 In the above code I add the class red to h1.
7- classList.add , classList.remove and classList.toggle
In the list, we can use classList and then add and remove class also we can toggle too.
Now move on towards innerHTML Using this we can change the text in real-time.