I am trying to do this:
$("#canvasDiv").mouseover(function() {
var pageCoords = "( " + e.pageX + ", " + e.pageY + " )";
var clientCoords = "( " + e.clientX + ", " + e.clientY + " )";
$(".filler").text("( e.pageX, e.pageY ) : " + pageCoords);
$(".filler").text("( e.clientX, e.clientY ) : " + clientCoords);
});
and in the console I get this:
Uncaught ReferenceError: e is not defined
I don't understand... I thought e
is supposed to be a variable that JavaScript has already set...help?
Answer: Execute Code after jQuery Library has Loaded The most common reason behind the error "Uncaught ReferenceError: $ is not defined" is executing the jQuery code before the jQuery library file has loaded. Therefore make sure that you're executing the jQuery code only after jQuery library file has finished loading.
The Javascript ReferenceError occurs when referencing a variable that does not exist or has not yet been initialized in the current scope.
The ReferenceError object represents an error when a variable that doesn't exist (or hasn't yet been initialized) in the current scope is referenced. ReferenceError is a serializable object, so it can be cloned with structuredClone() or copied between Workers using postMessage() .
Change
$("#canvasDiv").mouseover(function() {
to
$("#canvasDiv").mouseover(function(e) {
True, the first parameter to the callback is pre-defined, but in order to use it you must alias it through an argument name. That's why we specify e
as the argument. In fact, it's not required that the argument name is e
. This will work too:
$('#canvasDiv').mouseover(function( event ) {
});
But you must alias the event object through the name event
in the function callback.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With