We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

madmanlear on 04/24/08


Tagged


Versions (?)


Who likes this?

5 people have marked this snippet as a favorite

luman
orhanveli
martingoldszein
korzhik
netdunes


Basic Jquery Expander


Published in: JavaScript 


Very basic accordion effect Common structure would be an ID'd UL, and each LI to have a first child with the class of head Shows and hides siblings of .head, attaches ID of expanded to current element

  1. $.fn.expander = function() {
  2. $('.head', this).css("cursor","pointer");
  3. $('.head', this).siblings().hide();
  4. var expandedid = 'expanded';
  5. $('.head', this).bind('click', function() {
  6. $('#' + expandedid + ' .head').siblings().hide('slow');
  7. var currentid = $(this).parent().attr('id');
  8. $('#' + expandedid).attr({id: ''});
  9. if(currentid !== expandedid) {
  10. $(this).siblings().show('slow');
  11. $(this).parent().attr({id: expandedid});
  12. }
  13. return false;
  14. })
  15. }

Report this snippet 

You need to login to post a comment.