November 27, 201213 yr The code below simply shows and hides a div (content) when you click on the heading (heading). <script type="text/javascript"> jQuery(document).ready(function() { jQuery(".content").hide(); //toggle the componenet with class msg_body jQuery(".heading").click(function() { jQuery(this).next(".content").slideToggle(0); }); }); </script> Demo - http://www.designgala.com/demos/collapse-expand-jquery.html By default, the content is always hidden - Is there any way to have the content showing by default? I'm using a number of these on a page, some will need to be showing by default, others will have to be hidden. Just wondering how to maybe add a bit to the code to make both possibloe?
November 30, 201213 yr Refer this link.. http://webcloud.se/jQuery-Collapse/ there is a lots of options. Hopefully, your problem will be solved. Thanks Hem
November 30, 201213 yr <script type="text/javascript"> jQuery(document).ready(function() { jQuery(".content").hide(); jQuery(".content").eq(0).show(); // Shows the first one //toggle the componenet with class msg_body jQuery(".heading").click(function() { jQuery(this).next(".content").slideToggle(0); }); }); </script> If you want to show the second one , just add 1 to the parameter of .eq( ) . So this line will show the second element with a class of container : jQuery(".content").eq(1).show(); // Shows the second one A better way of doing this is by making a CSS class and add it to the element you want to be shown. .showContent { display:block; } Léon
December 22, 201213 yr $(document).ready(function() { $('#heading1').click(function() { $('#content1r').slideDown(); $('#content2, #content3').slideUp(); }); $('#heading2').click(function() { $('#content2').slideDown(); $('#content1, #content3').slideUp(); }); $('#heading3').click(function() { $('#content3').slideDown(); $(' #content1, #content2').slideUp(); }); }); </script>
Create an account or sign in to comment