August 31, 201610 yr 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
September 1, 201610 yr 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?
September 1, 201610 yr 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?
September 3, 201610 yr 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 September 3, 201610 yr by AblazeRich2
September 4, 201610 yr Try to add active:false after collapsible: true. Or: $( "#accordion" ).accordion({ collapsible: true, active:false });
September 4, 201610 yr 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