jQuery not removing "class" attribute name when using removeClass() -
i've written "favourite" feature (special entirely stefan hoth , reply previous article), — part — working. however, it's quirky.
firstly, after visting page, favourite button needs pressing twice before begins work, after works single click switch between states.
secondly, removeclass() method appears happy remove "active" part of class="active" attribute, weird.
function favouriteadd (){ $.ajax({ url: base_url + "bookmarks/jq_set_bookmark_as_favourite/add/" + $("a#favourite").data("bookmark"), success: function () { $('a#favourite') .addclass('active') .attr('title', "remove favorite") .unbind('click') .bind('click', favouriteremove); } }); } function favouriteremove (){ $.ajax({ url: base_url + "bookmarks/jq_set_bookmark_as_favourite/remove/" + $("a#favourite").data("bookmark"), success: function () { $('a#favourite') .removeclass('active') .attr('title', "add favorite") .unbind('click') .bind('click', favouriteadd); } }); } if($('a#favourite').hasclass('active') == true) { $('a#favourite').bind('click', favouriteremove); } else { $('a#favourite').bind('click', favouriteadd); }
i'm guessing solution elementary initiated, i'm sadly @ in elementary class when comes jquery.
try careful erase entire class attribute , if have additional classes in there wiped:
$('a#favourite').removeattr("class");
also, try putting if statement in ajaxcomplete function
$(document).ajaxcomplete(function() { // code here });
Comments
Post a Comment