SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [JQuery] Hide all other divs?

    I'm making an forum script with expandable comment boxes, and this works just fine ecxept 1 thing... When a comment div is expanded all other comment divs should close back... How do I do so?

    Code JavaScript:
    jQuery(document).ready(function() {
      jQuery("#content_full_<?=$newsid;?>").hide();
      jQuery("#content_small_<?=$newsid;?>").show();
      //toggle the componenet with class msg_body
      jQuery("#heading_<?=$newsid;?>").click(function()
      {
    	jQuery("#content_full_<?=$newsid;?>").fadeIn();
    	jQuery("#content_small_<?=$newsid;?>").hide();
      });
    });

    Thanks in advance ;-)

  2. #2
    SitePoint Enthusiast rainner's Avatar
    Join Date
    Apr 2011
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could give all your divs that will be contracting and expanding a common class name, this way is easy to target all of them at once from jquery.

    Code:
    jQuery( "#heading_<?=$newsid;?>" ).click(function()
    {
        jQuery( ".all_divs" ).each( function(){ $( this ).hide(); } ); 
        jQuery( "#content_full_<?=$newsid;?>").fadeIn(); 
    });


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •