Sometimes, after editing the content on your CMS Pages or Blocks, you may find yourself experiencing this console error on the frontend of your store, sometimes on specific pages, and sometimes on all pages. This can also be accompanied by loss of certain functionalities such as submenus not opening, store switcher dropdowns not working, etc.
In this article, we'll explore a potential cause and the solution for this type of error. This applies mostly to stores built with our Pearl Theme for Magento 2, however, it can apply generally in some cases as well.
This is what the error looks like in the console on the frontend:
In the case we're exploring, the error is caused by improper HTML code formatting relating to the Newsletter sections in certain CMS Pages and Blocks. The improper formatting is caused, in most cases, by the default Magento WYSIWYG Editor, which is oftentimes notorious for interfering with and breaking HTML code. You can read a bit more about why that should be disabled, and how to do it here in this article.
The improperly formatted code can look something like this, and it's usually found in the Newsletter section of CMS Pages or Blocks. If the error is showing up on all your pages, it's most likely in the Footer. In this example, we'll be taking Footer V3 from the Pearl Theme. The improperly formatted code can look something like this:
To fix the error, it's not enough to simply disable the WYSIWYG Editor, we'll also have to restore the code to the originally properly formatted version. The original version of all CMS Pages and Blocks included in the Pearl Theme can be viewed in the Pearl Theme Demo Admin here. Simply navigate to Admin > Content > Blocks > Footer V3 and find the original Newsletter section. We'll see here that the code is properly formatted, and we can replace the improper formatting with the correct one by copy-pasting the original code instead of the incorrect one.
After saving the Block and reloading the frontend, the error should be gone, and the functionality should be restored. You may also need to flush the Magento Cache from the Cache Management section as well, so try that if the error doesn't disappear after a simple reload.