Furthermore, it may occur when you have imported any jQuery library in the script tag. For example:
To solve the error, we recommend two following solutions.
How to solve this error?
Check the type of the object calling the addClass()
You should remember that this function addClass() only works if you are calling it from a set of jQuery elements. Therefore, you must make sure it is not an HTML element but a jQuery element, for example:
Also, make sure you have checked the spelling of the word ‘addClass’ because it is case-sensitive, and misspelling it will lead to an error.
Check if you have declared the jQuery library
As can be seen, we import the jQuery-min version as in the example above. Although there are many versions that contain this addClass function, we still recommend you use the latest version because it can help you avoid some other errors during use. Therefore, if you make changes to the version you are using, the results may not be what you expect. In many cases, loading jQuery multiple times or multiple versions on the same page can lead to this error, so please declare it once on each page to prevent the error.
Maybe you are interested:
- TypeError (intermediate value)(…) is not a function in JS
Name of the university: HCMUT