Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting "ReferenceError: getElementById is not defined"?

Tags:

javascript

I have a little JavaScript code I wrote, and for some reason I'm getting an error saying:

ReferenceError: getElementById is not defined 

Here is the function:

window.onload=function()  {      clearAll();      updatePizzaToppings();      updatePizzaToppings();      updatePizzaToppings();      updatePizzaToppings();  };   function updatePizzaToppings()  {      var checkBox=getElementById('selectBacon');      var pic=getElementById('BaconPic');      if (checkBox.checked)      {         pic.style.visibility='visible';      }     else      {         pic.style.visibility='hidden';     }            };  

I've made a little JSFiddle for it as well.

http://jsfiddle.net/CkjkB/5/

like image 422
novicePrgrmr Avatar asked Oct 22 '13 01:10

novicePrgrmr


People also ask

Why is my document getElementById returning NULL?

This error TypeError: document. getelementbyid(...) is null would seem to indicate that there is no such element with an ID passed to getElementById() exist. This can happen if the JavaScript code is executed before the page is fully loaded, so its not able to find the element.

What does getElementById return if not found?

The getElementById() method returns null if the element does not exist.

What is uncaught ReferenceError in Javascript?

The Javascript ReferenceError occurs when referencing a variable that does not exist or has not yet been initialized in the current scope. Reference errors in Javascript are of a few different types, with variations of each, that may get triggered in code. Some of these are discussed below.


1 Answers

You need to use document.getElementById()

like image 123
Iłya Bursov Avatar answered Oct 04 '22 07:10

Iłya Bursov