Okay, I'm under the impression that my current jQuery can be simplified (don't worry! It's short!) and I'm curious to know how this can be achieved. I think a solution to this will help produce a lot less code.
I currently have a list menu set up, with class names referring to their titles (HTML below) and if you click a list item, the menu item slides out and it's relevant content fades in. If you click the main heading again, the content fades out and the menu item slides back in.
Here's an example of my HTML
<ul class="wwd-filters">
<li><a class="corporate"><span>Corporate</span></a></li>
<li><a class="commercial"><span>Commercial</span></a></li>
<li><a class="construction"><span>Construction</span></a></li>
</ul>
<div class="wwd-content-each corporate">
<h2>Corporate</h2>
<div class="wwd-slides">
<div class="slides_container">
<p>Lorem ipsum lorem ipsum lorem ipsum</p>
</div>
</div>
</div>
<div class="wwd-content-each commercial">
<h2>Commercial</h2>
<div class="wwd-slides">
<div class="slides_container">
<p>Lorem ipsum lorem ipsum lorem ipsum</p>
</div>
</div>
</div>
Here's some example JS:
jQuery('.wwd-choices-container ul.wwd-filters li a.corporate').click(function () {
jQuery('.wwd-content-container .wwd-content-each').fadeOut();
jQuery('.wwd-content-container .wwd-content-each.corporate').fadeIn();
});
My problem is that I don't want to have to repeat the jQuery code for each list item and it's content (e.g. li a.corporate
, li a.commercial
, li a.li a.corporate
). As the class names for both the list item anchor and each content, is there an easy way to simplify this?
Everything is built via a CMS, so new sections and menu items would be added as time goes on so it has to remain as dynamic as possible. I'm thinking some form of array would work... and if it matches each other then it connections.