Ask coding questions

← Back to all posts
JavaScript Parameter problem
h
cuber1515 (94)

I'm trying to test something with parameters

So I made 2 headers 1st one with the the id="test1" and the second one with the id="test2", then underneath that I have to links the 1st one goes to #test1 and the 2nd one goes to #test2 and call the function changeColor(), but the function calls a parameter so it would be changeColor(test1) for the 1st link. This is the code for the function:

It doesn't work though. I did try this too:

And that actually worked but only for the second header. The only reason I tried this was bc I accidently did this in another repl and it worked.

If you look in script.js it has all of the functions but only the 1st one is not commented out.

Please help

P.S. If you want to help I would recommend forking it and uncommenting the functions to understand what's going on.

Answered by OldWizard209 (1702) [earned 5 cycles]
View Answer
Comments
hotnewtop
OldWizard209 (1702)

In the onclick function, you have to pass in the parameter as a string:

cuber1515 (94)

Thank you! @OldWizard209 you deserves some cycles!

OldWizard209 (1702)

No problem mate. It was a simple problem tbh. @cuber1515

cuber1515 (94)

True, but it was causing me a big problem in another repl, @OldWizard209