Reputation: 9
i have 3 box and applying this function but problem is when click on first box tab then action all boxes. i want to only one box response on first box tab. How is possible? and sorry for English mistake enter image description here
$(document).ready(function(){
$("ul#tabs li").click(function(e){
if (!$(this).hasClass("active")) {
var tabNum = $(this).index();
var nthChild = tabNum+1;
$("ul#tabs li.active").removeClass("active");
$(this).addClass("active");
$("#tab .li.active").removeClass("active");
$("#tab .li:nth-child("+nthChild+")").addClass("active");
}
});
});
Upvotes: 0
Views: 56
Reputation: 74738
Just noticed, seems you are having duplicate IDs for tabs
. Better to change it to class or give unique ID to each #tab
.
You have a .
before li
which is a tag and that changes it to class selector:
$("#tab li.active").removeClass("active");
$("#tab li:nth-child("+nthChild+")").addClass("active");
or you can use .eq()
method:
$("#tab li.active").removeClass("active");
$("#tab li").eq(nthChild).addClass("active");
Upvotes: 1