Show me the way
Show me the way
Can someone please take a look at the following code sample and show me a better approach? I know there has got to be a much cleaner way to write this.
- $('a.all').click(function() {
$('#filter-by a').removeClass('current');
$(this).addClass('current');
$('#results .video').fadeIn();
$('#results .article').fadeIn();
});
$('a.articles').click(function() {
$('#filter-by a').removeClass('current');
$(this).addClass('current');
$('#results .video').fadeOut();
$('#results .article').fadeIn();
});
$('a.videos').click(function() {
$('#filter-by a').removeClass('current');
$(this).addClass('current');
$('#results .article').fadeOut();
$('#results .video').fadeIn();
});
I have a set of results that are being returned and each result is given a class name depending on whether or not it's an article or video. I have three links at the top of the results container (all formats, articles only, videos only). If the user wants to only see videos, I am simply hiding all the divs with the article class (vise-versa for articles). Although the above code works... I am certain there is a much cleaner way to write it and I would like to learn this. Any help would be greatly appreciated. Thanks for looking.