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.

Expand/Collapse javascript code for paragraphs

Featured Replies

Hey everyone. I found this Javascript online. The only problem is that it doesn't automatically collapse the paragraph once you click another link to open another hidden paragraph. Does anyone know how to complete this Javascript so that the the open paragraph will collapse once another link is clicked to expand?

JAVASCRIPT

function toggleMe(a){

var e=document.getElementById(a);

if(!e)return true;

if(e.style.display=="none"){

e.style.display="block"

} else {

e.style.display="none"

}

return true;

}

HTML for each link to open paragraphs

<input type="button" class="button" onclick="return toggleMe('alright')" value="Alright" />

 

Thanks for any help you can provide.

 

Dave

If you're after the accordian effect you could try jQuery. Really lightweight too!

  • Author

The accordion is similar to what I had in mind, but not exactly. Let me expand a bit more on the desired effect.

 

I have a nav system setup on the right side of my page. I want the hyperlinks/button to trigger a show/hide accordion effect with <p> content that exists in the content portion of the page, which is located centered and to the left of the right nav system.

 

Here is the page so far, maybe this will help clarify.

http://www.db-elements.com/ahimsa/blake_ba...ndex_w_js2.html

 

If you click, for example, "Alright" in the right nav, the content for that link will appear under the links panel. But if you click the link right below it, it won't collapse the previous content that was open. I would like to have the accordion effect take place when someone clicks on the next link. Any ideas?

 

If not, I will probably go with the accordion effects you have suggested. This was the initial idea, as you can see by the remaining links in the content area, which have the same click & show effect for the paragraphs, but again, they will not collapse unless you manually click the link again.

 

Thanks for the help, by the way. Greatly appreciated from a newbie.

 

Dave

  • 5 months later...

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.