I have a jQuery onClick
handler, writed with an anonymous function like that:
$(\"#selector\").on(\"click\" function(){
// do something
})
<
Function namedFunction () {
alert("Hello world!");
}
$("#clickTester").on('click', namedFunction);
$("#clickTester").click(function(){
alert("Hello world!");
});
To pass custom parameters to namedFunction
use:
$("#selector").on("click", null, {param1: param1}, namedFunction);
namedFunction(event) { console.log(event.data.param1); }
try like
function namedFunction(){
alert("Hello world!")
}
$("#clickTester").on('click', namedFunction)
Updated Fiddle
Just pass the reference
of that function itself.
Try,
$("#selector").on("click", namedFunction);
Or a shorter version
$("#selector").click(namedFunction);
You don't need the ()
for your function here:
$("#selector").on("click", namedFunction)