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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -