If the returned object does not have the method change
means that this object is not a jQuery object.
To check if the $
variable is really jQuery you can check the contents of $.fn.jquery
.
If a string is printed as "1.12.4"
it is because $
is jQuery and the string represents the version. But this is not your case, because if it were not the error mentioned in the question would occur.
OK, we found that $
is not jQuery, the next step is to find out if jQuery was actually loaded. For this check the contents of window.jQuery
. If it is undefined
it is very likely that jQuery was not loaded with the page.
The only exception would be if there were some jQuery.noConflict()
in your code. Example:
// window.$ não é modificado. Apenas window.jQuery contém a lib
jQuery.noConflict();
// window.$ e window.jQuery não são modificados. Apenas window.jimCarrey contém a lib
let jimCarrey = jQuery.noConflict(true);
So after understanding the above concepts the walkthrough to find out would be:
>> $.fn.jquery
"1.12.4" // OK
>> $.fn.jquery
ReferenceError: $.fn is undefined // $ não é jQuery
>> jQuery.fn.jquery
"1.12.4" // OK, apenas $ não é jQuery
>> jQuery.fn.jquery
ReferenceError: jQuery is not defined // jQuery não carregado
>> jQuery.fn.jquery
ReferenceError: jQuery.fn is undefined // jQuery foi sobrescrito
If the above tests fail, give Ctrl + F and search for jQuery.noConflict
in your code. If you do not find it, it is not loaded.
Curiosity
If jQuery is not loaded as $('body')
does it return an HTML element correctly when I run it in the browser's console?!?!
Some modern browsers (such as Firefox , or Chrome and the Edge ) use $
as an alias to document.querySelector()
and $$
as alias to document.querySelectorAll()
cases these are not used by the page charged.