javascript - toggle button with font awesome and jquery -


i thought going simple, having bit of hard time getting work. able toggle once using .show , .hide, not able toggle back.

all appreciated.

here code:

<div class="middle">     <i class="fa fa-toggle-on fa-2x active" id="on" style="display:none;"></i>     <i class="fa fa-toggle-on fa-2x fa-rotate-180 inactive" id="off" ></i> </div>    $(document).ready(function(){      $('.middle').click(function(){         $('.inactive').show();         $('.active').hide();      })      .click(function(){         $('.inactive').hide();         $('.active').show();      });  }); 

i have pen of here: http://codepen.io/lucky500/pen/qdzple

one approach use toggle

$(document).ready(function(){     $('.middle').click(function() {         $('.inactive, .active').toggle();   }); }); 

http://codepen.io/moogs/pen/zgqpox


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -