Sunday 25 August 2013

jQuery script works only once

jQuery script works only once

script works only once, after that I need to refresh page to remove
favorite article (script is for that).
$("a.fav_no").on('click', function () {
var id = $(this).attr("id");
$(this).load("{$homepage}/user_action.php?action=fav&id="+ id
+"").addClass("fav_yes");
});
$("a.fav_yes").on('click', function () {
var id = $(this).attr("id");
$(this).load("{$homepage}/user_action.php?action=remove_fav&id="+
id +"").removeClass("fav_yes");
});
In console, I get id of article (div) on click after many times on click
(so it count) but it doesn't do anything. So I can right now just
favorite, to remove from favorites I need to refresh then to click again
on link to remove from favorites.
Thanks!

No comments:

Post a Comment