I am trying to create a messages widget that opens a message when the user clicks on its div and that gets refreshed every 30 seconds.
The problem is that after the widget gets refreshed the click functionality stops working. I am guessing that it has to do with the fact that the new elements added were not present when the click was set. And I tested it with firebug, if I run the script after the reload it works until the next refresh.
Does anyone know what is the proper way of resetting something like that after an ajax call?
I include my coffeescript code below:
refreshPartial = ->
$.ajax url: "refresh-messages-feed"
$(document).ready ->
myElem = document.getElementById("messagesFeed")
setInterval refreshPartial, 30000 if myElem?
$(".conversation").click ->
url = "/conversations/small/" + $(this).attr("id")
console.log url
$.ajax
url: url
cache: false
success: (html) ->
$("#conversation").html html