Toggle element in jQuery


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function initShowHideContent(){
  2. if($('a.show-hide').length){
  3. $('a.show-hide').each(function(){
  4. if($(this).hasClass('hide')){
  5. $(this).next().hide();
  6. }
  7. });
  8. $('a.show-hide').click(function(){
  9. $(this).next().toggle();
  10. if($(this).hasClass('hide')){
  11. $(this).removeClass('hide').addClass('active');
  12. }else{
  13. $(this).removeClass('active').addClass('hide');
  14. }
  15. return false;
  16. });
  17. }
  18. }

URL: http://jsfiddle.net/Alwaison/7d8Bu/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.