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 the jQuery you can check the content of $.fn.jquery
.
If you print a string like "1.12.4"
it is because $
is jQuery and the string represents the version. But this is not your case, because if it were, the error quoted in the question would not occur.
Okay, we found out that $
is not jQuery, the next step is to find out if jQuery was actually loaded. For that check the content 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 any 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 step by step to discover would:
>> $.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 a Ctrl + F and search for jQuery.noConflict
in your code. If not find is because it is not loaded.
Curiosity
If jQuery is not loaded as $('body')
returns an HTML element correctly when running in the browser console?!?!
Some modern browsers (such as Firefox, the Chrome and the Edge) use the $
as a alias for document.querySelector()
and $$
as alias for document.querySelectorAll()
where these are not used by the page loaded.
The fact that the "#" is missing from the selector should not be the cause of the cited error. At most the event would not be triggered. Try using
$("#idNewClient").on("change", function() {
– Sam
If the above suggestion shows the error "on is not a Function", then the problem is another.
– Sam
is sure that the
jquery
is loaded? if open the Developer tools and type for example$('teste')
what appears?– Ricardo Pontual
@Ricardopunctual I believe that if jQuery wasn’t loading it would make the mistake "$ is not defined"
– Sam
extly @sam, just to confirm if there is an error on the page, can be up to another script, just to remove the doubt
– Ricardo Pontual
To make sure that the jQuery is loaded just check if
$.fn.jquery
returns the jQuery version. If it returns everything is OK, otherwise it is because jQuery has not been loaded or overwritten.– fernandosavio