Passing the Event Object to a Function in Jquery -
typically, can pass event anonymous jquery function so:
$(".click_me").on("click", function(e) { e.preventdefault(); });
now let's remove anonymous function still want pass event it:
function onclickme(e){ e.preventdefault(); } $(".click_me").on("click", onclickme(e));
unfortunately, doesn't work expected. error:
referenceerror: e not defined
so how else can pass event external function?
just pass function reference, jquery handle passing arguments (it always passes event first argument handler function). so:
function onclickme(e){ e.preventdefault(); } $(".click_me").on("click", onclickme);
jquery function parameters
No comments:
Post a Comment