701 posts
  • Bought between 1000 and 4999 items
  • Canada
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
chrismccoy says

im using a popup box when i click a link

which is

$(”#search”).click(function(e) {

but i also want to create a shortcut

$.jQee(‘shift+s’, function(e) {

(shift+s) will open the box, is their anyway to combine them into 1 statement, so i dont have to copy the same function?

2004 posts
  • Has been a member for 4-5 years
  • Bought between 50 and 99 items
  • Exclusive Author
  • United States
Landonw says

Why don’t you use “jQuery.bind” ?

415 posts
  • Bought between 1 and 9 items
  • Europe
  • Exclusive Author
  • Has been a member for 4-5 years
osigrandi says

You could define the inner function as a named function I think:

http://stackoverflow.com/questions/336859/javascript-var-functionname-function-vs-function-functionname

Should save some space at least; too lazy to test, hope it works.

3365 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred more than 2000 users
  • Has been a member for 4-5 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+4 more
sevenspark Volunteer moderator says

Define a single function (with a function name), then just pass that function as a callback instead of using the anonymous function :)

Basic idea: http://jsfiddle.net/sevenspark/ESrS3/

701 posts
  • Bought between 1000 and 4999 items
  • Canada
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
chrismccoy says

thanks guys, ended up doing the function and calling it

by
by
by
by
by
by