How to delegate `hover()` function by using `on()`

<>

This question already has an answer here:

Answers


I think you'll need to unbind and add the hover handler. Also, you don't need the line continuations if you're indenting (in this case).

$( -> 

  #debugger 

  addFooDiv = -> 
    div = $('<div class="foo">This is another foo div</div>') 
    $(this).parent().append(div)
    addFooHandler()

  onLeaveHandler = -> 
    $(this).css "cursor", "pointer"  
    $(this).css "background", "white"

  onEnterHandler = ->   
    $(this).css "cursor", "default"  
    $(this).css "background", "lightblue" # so it's real obvious

  $('.appendFoo').on('click', addFooDiv)

  addFooHandler = ->   
    $(".foo").unbind("hover") 
    $(".foo").hover(onEnterHandler, onLeaveHandler)

  addFooHandler()
)

http://plnkr.co/edit/JbQtqIOhg2AHBCuoHs4N?p=preview

Props to Sethen Maleno: https://stackoverflow.com/a/9827114/30946


Need Your Help

WCF service fires event itself

c# wcf events wcf-client

Is it possible to fire event from service to connected clients without request from client? (I know, if I use client request I could use callback)

Optimal endianness conversions and signed integers

c type-conversion endianness

I am looking for the fastest way to read numerical values stored in binary files.