addeventlistener js to change style
var button = document.querySelector("button");
button.addEventListener("click", function() {
const curColour = document.body.style.backgroundColor;
document.body.style.backgroundColor = curColour === 'red' ? 'blue' : 'red';
});
4.3
10
var button = document.querySelector("button");
button.addEventListener("click", function() {
const curColour = document.body.style.backgroundColor;
if (curColour === 'red') {
document.body.style.backgroundColor = "blue";
}
else {
document.body.style.backgroundColor = "red";
}
});
Thank you!
10
0
Are there any code examples left?
New code examples in category Javascript