I have a tab system set up that uses the following structure to automatically detect new tabs:
<a href="#div1id">Show div 1</a>
<div id="div1id">Div1</div>
The thing is, I need to disable the ability to reload a tab by clicking the tab that is already showing. I have tried using .hasClass() and .is() to detect if the clicked tab was already had ‘.active’ applied to it, but with no luck.
Here is my current code for the animation and changes:
$(document).ready(function(){
$("#tabs li").click(function() {
$("#tabs li").removeClass('active');
$(this).addClass("active");
$(".content").hide();
var selected_tab = $(this).find("a").attr("href");
$(selected_tab).fadeIn();
});
});
You can use
.delegate()to both make it a bit more efficient and solve your issue, like this:Bu using
:not(.active)in the selector, theclickhandler will only execute if it does:not()have the.activeclass…also you have one event handler instead ofnevent handlers, one for each<li>.