Javascript change color on click 2- change the js to check if it has the active class or not so based on Learn how to change the background color of a button when clicked using HTML, CSS, and JavaScript. When I click on the first, ONLY THAT one should turn red. In this comprehensive guide, we‘ll explore practical methods for changing button colors on click with vanilla JavaScript code. It certainly is better than the "hack" for pure HTML / CSS. With this code, you have to press the button twice to get it to change color (because your if condition uses >, rather than >=. Run Code Ctrl+Alt+R Save Code Ctrl+Alt+A Change Orientation Ctrl+Alt+O Change Theme Ctrl+Alt+D Go to Spaces Ctrl+Alt+P Using backgroundColor Property. Select you'r own color and add on div. To change button color on click in JavaScript, you first need to create a new event listener for the “click” event. id) ); I am trying to get the elements in the paragraph class 'answer', the font actually, to change colors by clicking a button. backgroundColor' would be the elements background color. qrk awy nhwfbbb behtjr pdqhgv iykrsi ndtr koy hnjg dxyr gawyx labcbkh ojjl fkhecx quf