Ask coding questions

← Back to all posts
[JS] Style changing wont work
MrVoo

I'm trying to change the style of every paragraph with this code:

But it doesn't work, I get an error saying TypeError: undefined is not an object
Send help?

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
MrVoo
Comments
hotnewtop
Coder100

getElementsByTagName returns an array.
Try:

or try:

MrVoo

@Coder100 Is there an easy way I can change everything in the array with a loop (first option)? I'm not very good at JavaScript :P

Coder100

yes

that is for if order does not matter, which is for most use cases.
@MrVoo

VulcanWM

Hey can you attach the repl with the error? Thanks