Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Collapsible Div Addition

Featured Replies

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?

<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

  • 4 weeks later...
$(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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.