Reputation: 2708
I have a TooltipView that pops up whenever an element with class .tooltip
is moused-over and takes the content of that elements data-tooltip
attribute and displays it in the tooltip.
I bind the events for TooltipView in it's initialise function but the problem is if another view is dynamically created, or re-rendered then TooltipView doesn't know about it.
var tooltipView = Backbone.View.extend({
el: '#tooltip-container',
initialize: function() {
$('.tooltip').on('mouseover', function() {
....
}
}
}
I know I can manually trigger events from each of the views when they're rendered but is there away to do it just from within TooltipView?
I'd like TooltipView to listen for ANY view to render and then re-render itself.
Upvotes: 0
Views: 171
Reputation: 3188
Maybe attaching events to higher DOM level would work for you:
initialize: function() {
$('body').on('mouseover', '.tooltip', function() {
....
}
}
Don't forget to unbind it later though
Upvotes: 3