1

I am using jQuery version 1.4.1. I try to attach resize & click events this way but it is not working.

var $els = [];
$els.window = $(window);
$els.window.bind('resize', getNewWindowCorner());
$els.toggleUPSButtons.bind('click', toggleUPSOverlay());

Help would be appreciated. Thanks.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Thomas
  • 33,544
  • 126
  • 357
  • 626

3 Answers3

1

You want to give the reference of the function to the handler, not the returned value. Remove the trailing brackets:

$els.window.bind('resize', getNewWindowCorner);
$els.toggleUPSButtons.bind('click', toggleUPSOverlay);
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
1

One different way is as follows if you want to call the functions yourself.

var $els = [];
$els.window = $(window);

$els.window.bind('resize', function(){
 getNewWindowCorner();
});

$els.toggleUPSButtons.bind('click', function(){
 toggleUPSOverlay();
});
Xmindz
  • 1,282
  • 13
  • 34
0

If you are using $els.window.bind('resize', getNewWindowCorner()); function executed immediately,so remove bracket

$els.window.bind('resize', getNewWindowCorner);
$els.toggleUPSButtons.bind('click', toggleUPSOverlay);
Balachandran
  • 9,567
  • 1
  • 16
  • 26