Tuesday, July 23, 2013

BackboneJS: click event is being triggered twice

In the view definition I had:

...
...
 // events
    ,events: {
        'click ': 'selectServiceEvent',
        'click a': 'learnMoreLinkEvent'
    }
...
...
,selectServiceEvent: function () {
        this.clickCard(); 
}

But when I was clicking the div generated by de view, the selectServiceEvent function was being triggered twice. The solution was add return false; to the selectServiceEvent function:

,selectServiceEvent: function () {
        this.clickCard(); 
        return false;
}

2 comments:

Eric said...

Almost one year later, I came across this blog while looking for an answer to a similar problem. Your solution worked. Thank you so much!

Raiden said...

this didn't work for me ... any reason why it's not working??

Thanks