I know this may be a very basic question, sorry if it is but in javascript/jquery i sometimes come into contact with a function having a random parameter that doesn’t seem to serve an obvious purpose, such as this one below used on the jquery website.
$("div").mousemove(function(e){
var pageCoords = "( " + e.pageX + ", " + e.pageY + " )";
var clientCoords = "( " + e.clientX + ", " + e.clientY + " )";
$("span:first").text("( e.pageX, e.pageY ) : " + pageCoords);
$("span:last").text("( e.clientX, e.clientY ) : " + clientCoords);
});
Here the function has a parameter of e, i don’t get why though i know if it didn’t have an e it could also work because that’s how i tend to use javascript. Why would a programmer do this?
The
erepresents the event object. In the example given, the user needs the event object so that he/she can access the location of the cursor on the screen when the mousemove event is fired, using thepageXandpageYproperties of the event (e) object.