harpax
harpax

Reputation: 6106

jquery ui: Is there a way to distinguish a 'real' event from an api call?

I am using tabs from jquery ui where a select-callback is included, working as expected. At one point of the script I need to do a select-method call that also triggers the callback which is not wanted at that point.

What I am looking for is some difference in the event-parameter of the callback which could be used in an if-clause to prevent the contents from the callback to be executed..

I tried stopPropagating, but then the default tab functions are not executed either (the classes are not reset)

I hope someone understands what I am looking for :)

thanks in advance

Upvotes: 1

Views: 99

Answers (1)

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76880

To distinguish a real event from a programmatically generated one you should check for event.originalEvent wich is undefined if the event is generated programmatically

for example:

<button id='my'>Click me</button>
<button id='my2'>Click the other</button>

$('#my2').click(function(){
    $('#my').click();
});

$('#my').click(function(event){
    if (event.originalEvent === undefined){
        alert('computer');
    }else{
        alert('human');        
    }
});

fiddle here: http://jsfiddle.net/uqNHd/

Upvotes: 1

Related Questions