+ 5
Can we use classes insted of id in JavaScript?
3 Answers
+ 6
Sure. If the class is only assigned to one element, you can easily get the element. If the class is assigned to multiple, you need to know the creation order so you can access the one you want.
classes = document.getElementsByClassName("mine");
classes[0] is first
classes[9] is tenth.
+ 4
yes classes can be used instead of an id.. Classes and Ids are like hooks. See link below for more explanation
https://css-tricks.com/the-difference-between-id-and-class/
0
Possible.
It will depend of the way you use it.
Eg. The document.getElementByclass(). only if you it before as in html <div class="myclass">Here you done it</div>.
The same way you called 'id'.
Correct it if you want, I am yours.