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.

Div that appears onclick

Featured Replies

Hi All,

Working on an old website that needs an online shop added to it.

There are a lot of product types for each product (up to 40 variations in some cases). So we wanted the listings of these products to appear / disappear when a button is clicked.

What is the best way to do this? Can it be done with straight HTML (seem to remember something about it being possible in HTML 5 or CSS 3 but maybe I'm wrong) or is Javascript / Jquery necessary?

Does anyone have any sample code they could give me?

Kind Regards

Rich

 

 

Hi!
It depends on the reason why you want to hide or show the product types. If the page would be too long if everything would be visible, then you can collapse and expand the types.

Examples for this:
https://jqueryui.com/accordion/#collapsible

http://v4-alpha.getbootstrap.com/components/collapse/

 

Is this what you are looking for?

Sorry it might be easier if we understood a little more.

 

There are a lot of product types for each product (up to 40 variations in some cases). So we wanted the listings of these products to appear / disappear when a button is clicked.

 

So just to get my head around this, you have a listings page e.g. /products/garden/benches/ and on this page you list say your garden benches so a bit like...

<div>
<h2>Simple Bench</h2>
<p>A simple bench available in 43 wood varieties.</p> 
<dl>
<dt>Price</dt>
<dd>£14.99</dd>
​</dl>
<a href="/product-details/premium-bench">View Product</a>
</div>
<div>
<h2>Premium Bench</h2>
<p>Our premium bench available in 22 wood varieties.</p>
<dl>
<dt>Price</dt>
<dd>£19.99</dd>
</dl>
<a href="/product-details/premium-bench">View Product</a>
</div>

Then on /product-details/premium-bench you want to show / hide each 'wood variety' e.g. default to 'Oak' then they click to show the other varieties?

  • Author

Sorry if I wasn't very clear. But you have more or less got it. The issue these guys have is that they are an engineering company in a small niche market with highly bespoke products. So the pages are very information heavy to try and explain what these products are.

The idea is to save space. It is more of an enquiry basket form because of the bespoke nature of the products involved.

 

Here is a link to the test page I've been working on.

http://www.mason-uk.co.uk/flexible-pipe-connectors2.asp

 

Scuse the design, slightly scruffy in places, but the tarting up can come later once the bones are functioning.

 

That Jquery code you gave me works great Milli05. But how do I set the default to hide? So the DIV doesn't load open but they viewer has to click to view it?

 

Thanks!

Edited by AblazeRich2

Try to add active:false after collapsible: true. Or:

 

$( "#accordion" ).accordion({
collapsible: true,
active:false
});
  • Author

Thanks guys,

Span, your code didn't work, for some reason everything stopped functioning.

It seems like the Jquery is adding stuff to my Divs and styles throughout the code.

I have been experimenting with having a couple of sections in my website in the accordion but for some reason the drop down Divs are coming out massive, and nothing I do to the css (inline or external stylesheet) seems to make a difference. I have looked at the Jquery files, but I can't see what is doing it...

Any idea on how to fix it? Is there a way I can over-ride the styles that the Jquery seems to be adding?

http://www.mason-uk.co.uk/flexible-pipe-connectors2.asp

 

Thanks so much guys

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.