Jump to content

Recommended Posts

Hello,

 

I have the following HTML markup:

 

<div class="filter">
<h3>Filter</h3>
<ul>
	<li><a href="#all" title="All">All</a></li>
	<li><a href="#brand" rel="brand" title="Brand">Branding</a></li>
	<li><a href="#iphone" rel="iphone" title="iPhone">iPhone</a></li>
	<li><a href="#web" rel="web" title="Web">Web</a></li>
</ul>
</div>
<div class="projects">
<div class="project iphone"></div>
<div class="project iphone"></div>
<div class="project web"></div>
<div class="project branding"></div>
</div>

 

What I want to do, is click on the filter parameters, and only show the content that it relates to.

 

So for example, clicking on iPhone, will only show the iPhone related projects.

 

Here is my jQuery:

 

$('.filter li a').click(function(){

$('.projects .project').fadeOut();

var content = $(this).attr('href');
var contentClass = content.substring(1,content.length);

if(contentClass == 'all') {
	$('.projects .project').fadeIn(); 
} else {
	$('.projects .project').hasClass(contentClass).fadeIn();
}
return false;

});

 

This currently doesn't work.. Does anyone understand how I can resolve this? Or maybe there is a better way to write what I am trying to do?

 

Cheers.

Link to comment
https://forums.phpfreaks.com/topic/217682-jquery-showhide-help/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.