+ 1

Why doesn’t the color of the text change back to green?

https://code.sololearn.com/Whv65FF6rs96/?ref=app There are 3 paragraphs. 1) When you click on them, I want the 1 you clicked on to turn green and then the other 2 to turn red. 2)Then when you click another, for the the other 2 to turn green and the selected 1 to turn red. The first step happens, but the second one doesn’t. Instead, they just stay green and you get 2 greens and 1 red. I change the color of all the elements in the 1st line of the function. On the 2nd line I change the element selected.

30th Jan 2019, 6:20 PM
Thomas Czernek
Thomas Czernek - avatar
1 Answer
+ 3
Thomas Czernek When you change style with javascript you are changing the inline style. Inline style takes priority over the internal style sheet and the external style sheet. So when changing the text color to green you are changing it by inline style. Hence the reason the text color for the other divs doesn't change. https://www.w3schools.com/css/css_howto.asp You can put an event listener on the items div and use event delegation to toggle between the two colors. https://code.sololearn.com/WE9XEgJmFldE/#js
30th Jan 2019, 8:47 PM
ODLNT
ODLNT - avatar