Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Created September 4, 2013 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheeyeo/6435628 to your computer and use it in GitHub Desktop.
Save cheeyeo/6435628 to your computer and use it in GitHub Desktop.
Rails 3.2 jquery 'live' action being updated with 'on' for UJS.
var like_enter = function(){
$(".already_liked").find('.title').text('Unlike It');
$(".already_liked").find('i.icon-circle').addClass('unliked-circle');
$(".already_liked").find('i.icon-light').removeClass('icon-heart').addClass('icon-remove');
}
var like_leave = function(){
$(".already_liked").find('.title').text('Like It');
$(".already_liked").find('i.icon-circle').removeClass('unliked-circle');
$(".already_liked").find('i.icon-light').removeClass('icon-remove').addClass('icon-heart');
}
$(document).on("mouseenter", "a.already_liked", like_enter);
$(document).on("mouseleave", "a.already_liked", like_leave);
@cheeyeo
Copy link
Author

cheeyeo commented Sep 4, 2013

The above example lives within the main application JS file. In order to rebind the mouseenter and mouseleave events within a UJS response they must be redefined in the context of the document object else it will not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment