jQuery - Toggle Multiple Elements


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

I used this simple snippet to enable users to "View More Info" which was embedded in a div below each of a list of items. This is different from many of the simple jQuery examples that only allow you to show/hide one particular div.


Copy this code and paste it in your HTML
  1. <!-- jQuery Code -->
  2. $(document).ready(function() {
  3. $('#commentbox').hide();
  4.  
  5. $('a.comment').click(function() {
  6. var id = $(this).attr('id');
  7. $('#commentbox' + id).toggle(500);
  8. // alert(id);
  9. return false;
  10. });
  11.  
  12. });
  13.  
  14.  
  15. <!-- HTML -->
  16.  
  17. <div class="story">
  18. <div class="storytitle">hello</div>
  19.  
  20. <div class="storybg">blah blah blah</div>
  21. <div class="storybottom"><a href="#" id="3242" class="comment"
  22. name="3242">comment</a></div>
  23. <div id="commentbox3242" class="commentbox"
  24. style="display:none">comment form</div>
  25. </div>

URL: http://www.aristoworks.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.