JavaScript Error: Uncaught TypeError Cannot Read Properties of Null or Undefined
The script used something that did not exist yet. Check the element, load order and data.
Reference guide. This guide is written from established practice and the official documentation of the tools involved. We have not yet tested every step on a live demo site. Back up your site before you change anything.
What it means
Code tried to use a property of something that is null or undefined, such as an element not found on the page.
Fix
- Read the line number in the console error. See reading the browser console.
- Is the script running before the element exists? Move it to the end of the body or wait for the page to load.
- Does the selector match the element? Typos in IDs and classes are common.
- Is the element present on only some pages? Check for it before using it.
- Is the data (from an API) empty? Check the response first. See JavaScript fetch() Fails: 'Failed to Fetch' and Network Errors Explained.
Related guides
- WPForms or Gravity Forms Entries Not Saving
- WordPress Shows the Wrong Time or Publishes at the Wrong Time
- Where to Add Custom CSS or Code in WordPress Without Losing It After Updates
- "The Uploaded File Exceeds the upload_max_filesize" in WordPress: Fix
Did this solve it? If not, email hello@sitefixlab.org with the exact error text and we will look into it. Try the problem finder.