0

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");
    }
 });
 });

1 Answer 1

1

Note:

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"); 
Sign up to request clarification or add additional context in comments.

2 Comments

` $(".tabid .li.active").removeClass("active"); $(".tabid .li:nth-child("+nthChild+")").addClass("active");` not working :(
i want to change these both line $(".tabid .li.active").removeClass("active"); $(".tabid .li:nth-child("+nthChild+")").addClass("active"); with different class ".tabid123 .li.active" and ".tabid456 .li.active" ... so on, when a mysql array loop executed and click on tab show effect only current box no all. please help me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.