+ 1

How do i add a class in an ID?, and if it cant be done, how can i get element by class name?

How can I add a class to an id? I have tried it several times and apparently it cannot be, I tried to add a class to another class with javascript, but it turns out that it is somewhat complicated to obtain an element with getElementsByClassname, something about which returns an array and it should be traversed etc, but I go back to the problem at the beginning, could someone give me an example of how it should be done correctly?

4th Dec 2020, 3:13 AM
Sam Vásquez
Sam Vásquez - avatar
4 Respuestas
+ 7
Sam Vásquez Try to use .getElementById(youridhere) This will help you :)
4th Dec 2020, 6:04 AM
Piyush
Piyush - avatar
0
Wait, what did you mean? Did you ask how do you combine a class to an ID?
4th Dec 2020, 3:20 AM
:DD
:DD - avatar
0
Yes, how add a class to an id
4th Dec 2020, 3:22 AM
Sam Vásquez
Sam Vásquez - avatar
0
Piyush[21 Dec❤️] but, if i use getElementById, i dont can add class with javascript later :(
5th Dec 2020, 4:53 AM
Sam Vásquez
Sam Vásquez - avatar