Monday 29 July 2019

javascript - Uncaught TypeError: Cannot set property 'onclick' of null

I'm having problems making my window alert pop up with a simple checkbox and can't for the life of me figure out why. Here's the basic Javascript and HTML:






var blue_box=document.getElementById("color-blue");
function colorFunction() {
window.alert("This color is blue!");
}

blue_box.onclick=colorFunction;



Form!
















Which throws: Uncaught TypeError: Cannot set property 'onclick' of null
under



blue_box.onclick=colorFunction;



Are there any visible reasons for this error in my code?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...