2 years ago

#29369

test-img

Roland

Add class using getElementsByClassName with in HTML

I want to add a class (underline) to each element with rel_row_0 class.

I have this code:

<a onclick="document.getElementsByClassName('rel_row_0').classList.add('underline');">X</a>

I having this error message: Uncaught TypeError: Cannot read properties of undefined (reading 'add') at HTMLAnchorElement.onclick

Usually I don't use javascript so i'm not that good at it.

Thanks for all the help!

javascript

html

getelementsbyclassname

0 Answers

Your Answer

Accepted video resources