I want something like this:
div.onclick = function(x, y);
How can I do this without executing the function?
I don't want to use jQuery.
Putting () after the function will call it. So don't do that.
div.onclick = function; // Note: function is a keyword and can't really be used as a variable name
That won't call the function with the arguments you want though. Event handler functions are always called with one argument: the event object.
You need to create a new function to call yours with those arguments.
function myhandler(event) {
function(x, y); // Still not a valid name
}
div.onclick = myhandler;
var NewFunction = function(x){
// your function code
};
div.onclick = NewFunction;
NewFunction is called, it will be passed one argument (the event object) but you've written it to expect two arguments. Function names starting with capital letters are traditionally reserved for constructor functions in JavaScript, and this isn't one.
addEventListenerfor itbind