javascript - Buttons that changes state to refresh Jquery -
i have sample:
http://jsfiddle.net/jfgve/1017/
code html:
<i class="fa fa-circle-o circle crad" id="radio"></i> <i class="fa fa-circle-o circle crad" id="radio"></i> <i class="fa fa-circle-o circle crad" id="radio"></i> <i class="fa fa-circle-o circle crad" id="radio"></i> <i class="fa fa-circle-o circle crad" id="radio"></i>
code js:
var firstbuttonobject = localstorage.getitem('class'); if(firstbuttonobject){ $('.crad').addclass(firstbuttonobject); } $('.crad').click(taskfunction); function taskfunction(){ if ( $( ).hasclass( "fa-circle" ) ) { $( ).removeclass('fa-circle').addclass('fa-circle-o'); localstorage.setitem('class', 'fa-circle-o'); }else{ $(this).removeclass('fa-circle-o').addclass('fa-circle'); localstorage.setitem('class', 'fa-circle'); } }
the problem when click on button , ... colored refresh want stay clicked ...
for example, if click on 3 buttons of 5 full circle 3
how can solve problem?
thanks in advance!
var defineclass = ''; $('.crad').each(function( index){ defineclass = localstorage.getitem('class' + index); $(this).addclass(defineclass) }); $('.crad').click(taskfunction); function taskfunction(){ if ( $( ).hasclass( "fa-circle" ) ) { $( ).removeclass('fa-circle').addclass('fa-circle-o'); localstorage.setitem('class' + $(this).index(), 'fa-circle-o'); }else{ $(this).removeclass('fa-circle-o').addclass('fa-circle'); localstorage.setitem('class'+$(this).index(), 'fa-circle'); } }
store class info based on index wise.
Comments
Post a Comment