Answers for "change the body background color with javascript checkbox using"

0

change the body background color with javascript checkbox using

blue=document.getElementsByClassName("check1")[0]
red=document.getElementsByClassName("check2")[0]
yellow = document.getElementsByClassName("check3")[0]
function colors(color) {
    document.body.style.backgroundColor = color;
}
 blue.addEventListener("click", e => {
     if (blue.checked) {
         colors("blue")
     }
     else if (red.checked) {
         colors("red")
     }
     else if (yellow.checked) {
         colors("yellow")
         }
     else {
    colors("white")         
     }
 })

red.addEventListener("click", e => {
    if (red.checked) {
       colors("red")
    }
    else if (blue.checked) {
        colors("blue")
    }
    else if (yellow.checked) {
        colors("yellow")
    }
    else {
     colors("white")
    }
})
yellow.addEventListener("click", e => {
    if (yellow.checked) {
     colors("yellow")
    }
    else if (red.checked) {
        colors("red")
    }
    else if(blue.checked){
      colors("blue")
    }
    else {
       colors("white")
    }
})
Posted by: Guest on March-16-2021

Code answers related to "change the body background color with javascript checkbox using"

Code answers related to "Javascript"

Browse Popular Code Answers by Language