views:

22

answers:

2

According to the jQuery manual you can send extra parameters (as an array) when calling a trigger. I am using this at the moment:

$('#page0').trigger('click', [true]);

How would I pick up whether the paramter has come through or not when using this?

$('ul.pages li a').click(function() {
  // Do stuff if true has been passed as an extra parameter
});
+1  A: 
$('ul.pages li a').click(function(event, param) {
  if (param) {
    // Do stuff if true has been passed as an extra parameter
  }
});

If the click event was triggered normally, param will be undefined and body of the if statement won't execute.

interjay
A: 

You could also use the arguments array without specifying a permanent function prototype (arguments[0] is the event itself):

$('.post-text').click(function() {
    if(arguments[1]===true) {
        // do something
    }
});

$('.post-text').trigger('click',[true]);
Simon Scarfe