# JavaScript – On document ready (Snippet)

Common use is let’s say you want to change color to an element to red, but when you run it you get a console error telling you that the element doesn’t exist, depending on your code structure, it is possible that this code is running before that element has even rendered and added to the document.
So to prevent this you tell the browser to execute your code only after the document has been fully rendered and loaded.

Any JS code that is inside of this function will run only after the browser rendered and loaded the whole document.

  // do stuff after document is ready.