Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught ReferenceError: e is not defined

Tags:

jquery

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?

like image 848
Bryce Avatar asked Nov 10 '12 21:11

Bryce


People also ask

How do I fix uncaught ReferenceError is not defined?

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.

What is uncaught ReferenceError in JavaScript?

The Javascript ReferenceError occurs when referencing a variable that does not exist or has not yet been initialized in the current scope.

What is ReferenceError?

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() .


1 Answers

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.

like image 72
David G Avatar answered Sep 22 '22 01:09

David G