701 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Located in Canada
  • Has collected more than 1000 items on Envato Market
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?

2061 posts
  • Has collected 50+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in United States
Landonw says

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

415 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 1+ items on Envato Market
  • Located in Europe
  • Sells items exclusively on Envato Market
+2 more
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.

3445 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark 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
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Located in Canada
  • Has collected more than 1000 items on Envato Market
chrismccoy says

thanks guys, ended up doing the function and calling it

by
by
by
by
by
by