javascript - Keep toggle and add class active with JQuery through pages refresh -
i used onclick function , when click functions addclass , toggle events added function. once when activate toggle , addclass , refresh page addclass getting removed , toggle events running beginning. how avoid the removal of class , toggle function on page reload?
jqry("#wrap").delegate('img.favourite', 'click', function() { var toggle = $(this).data("toggleflag") || false; var check_fav = jqry(this).hasclass('switcher-active'); var id = jqry(this).attr('pid'); if (!toggle && !check_fav) { jqry(this).addclass('switcher-active'); alert("test1"); } else { jqry(this).removeclass('switcher-active'); alert("test2"); } $(this).data("toggleflag", !toggle); }); <img class="favourite" src="images/fav.png" alt="favourite" > the above code not working properly. getting addclass('switcher-active') active , getting alert test1 on first click , removeclass('switcher-active') , alert test2 on second click. when refresh page after first click i.e after addclass('switcher-active') active must continue removeclass('switcher-active') , alert test2. on page refresh addclass('switcher-active') inactive , alerted test1. how test2 , removeclass('switcher-active') after page refresh. how possible?
Comments
Post a Comment