I'm trying to learn how to think in terms of logic when using jquery or programming in general; so far I'm having this issue:
HTML
<div id="content">
<a href="#" class="blog">Blog</a>
<a href="#" class="portfolio">Portafolio</a>
<div id="portfolio">
<ul>
<li>Item Portafolio</li>
<li>Item Portafolio</li>
<li>Item Portafolio</li>
</ul>
</div>
<div id="blog">
<ul>
<li>Item Blog</li>
<li>Item Blog</li>
<li>Item Blog</li>
</ul>
</div>
</div>
jQuery
(function() {
var blog = $('#blog'),
portfolio = $('#portfolio');
blog.hide();
portfolio.hide();
$.fn.fadeSlideToggle = function(speed, fn) {
//fadeToggle = opacity
//slideToggle = height
return $(this).animate({
"height" : 'toggle',
"opacity" : 'toogle'
}, speed || 400, function() {
$.isFunction(fn) && fn.call(this);
});
};
$('a').on('click', function(e) {
e.preventDefault();
var myString = "#" + $(this).attr('class');
blog.hide(300);
portfolio.hide(300);
$(myString).fadeSlideToggle(800);
});
})();
Basically, it works fine, when you click the blog button, it display the blogs div, when you click the portfolio button it displays the portfolio div, however, problem begins when I click blog and then click blog again, same with the other, my logic hide the divs and show it again, I just want to find a logic that allows me to do nothing if I click the same anchor tag several times and only change if I click other.
Any help??
Thanks in advanced.