Why do all my buttons turn green when I use coloredButton(function,color) function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why do all my buttons turn green when I use coloredButton(function,color) function?

When I use the following code, all buttons are green. Why? and how do I fix this? code: ``` var coloredButton = function coloredButton(func, color="white") { this.func = func; this.color = color; document.write("<style>input {background-color:"+color+"; color:"+color+"; font-size:200%;}</style>"); document.write("<input type=\"button\" value=\"----------\" onclick=\""+func+"\"/>"); } var BA = new coloredButton("alt1()","red"); var BB = new coloredButton("alt2()","blue"); document.write("<br/>"); var BC = new coloredButton("alt3()","yellow"); var BD = new coloredButton("alt4()","green"); function alt1() { alert("hi"); } function alt2() { alert("bye"); } function alt3() { alert("enter"); } function alt4() { alert("exit"); } ```

21st May 2019, 5:42 PM
CALIN BAENEN
CALIN BAENEN - avatar
2 Answers
+ 4
I changed a lot ... But you should imagine each element as unique, you should not create multiple styling tags, because they serve all the elements of the page and the last one is always what the browser uses. https://code.sololearn.com/WAcCmrahV548/#html
21st May 2019, 6:06 PM
Jônatas Araripe
Jônatas Araripe - avatar
+ 1
Thanks Jônatas Araripe!
21st May 2019, 6:17 PM
CALIN BAENEN
CALIN BAENEN - avatar