jQuery function in .click() etc
Posted
by Martind
on Stack Overflow
See other posts from Stack Overflow
or by Martind
Published on 2010-04-07T17:51:13Z
Indexed on
2010/04/07
17:53 UTC
Read the original article
Hit count: 236
Hi all.
So normally, I do it like this:
$('#selectRoom a').click( function(e) {
e.preventDefault(); // To prevent the default behavior (following the link or adding # to URL)
// Do some function specific logic here
});
However, I would like to do it like this, to clean things up (and be able to reuse):
$('#selectRoom a').click( selectRoom );
function selectRoom () {
e.preventDefault(); // To prevent the default behavior (following the link or adding # to URL)
// Do some function specific logic here
}
The problem is, i cant pass the "e" event-handler to the function, then the selectRoom() function is called on load. i.e:
$('#selectRoom a').click( selectRoom(e) );
Can I fix this somehow?
© Stack Overflow or respective owner