Using a Backbone.js View, say I want to include the following events:
events: {
\'click a\': \'link\',
\'click\': \'openPanel\'
}
Two other methods that might work for you:
events: {
'click a': 'link',
'click *:not(a, a *)': 'openPanel'
}
Then openPanel will not capture click
events on any or child of an
(in case you have an icon in your
tag).
At the top of the openPanel
method, make sure the event target wasn't an :
openPanel: function(event) {
// Don't open the panel if the event target (the element that was
// clicked) is an or any element within an
if (event && event.target && $(event.target).is('a, a *')) return;
// otherwise it's safe to open the panel as usual
}
Note that both of these methods still allow the openPanel
function to be called from elsewhere (from a parent view or another function on this view, for example). Just don't pass an event
argument and it'll be fine. You also don't have to do anything special in your link
function -- just handle the click event and move on. Although you'll probably still want to call event.preventDefault()
.