I have a hover event in backbone like this:
events:
'mouseover .1_select' : 'hover'
'mouseover .2_select' : 'hover'
I am then trying to change the same CSS value on the element that has been “hovered over”…
hover: (e) ->
$(this.el).css('background-position' : '0px -40px')
What I need to do is take the event “e” and find our from it which element has been hovered over and update the css on that one only.
At the moment I can see myself writing the function out twice for each class but I do not want to do that – it feels messy. For example the class changes but the property and value I need to change stays the same.
use
$(e.currentTarget)instead of$(this.el)to modify the current target element of an event to which the event was bound. Thanks to jQuery currentTarget is normalized across browsers and you don’t have to worry about anything 🙂and you can use
this.$elrather then$(this.el)as ofBackbone 0.9to save some memory and keep your code cleaner