0

Someone help me how to add css class with jquery? I've bootstrap tab content with the current class have a class "active".

 <div class="tab-content">
   <div class="tab-pane **active**" id="one">
      <div class="row">

and my other tab code is:

    <div class="tab-pane" id="two">
        <div class="row">
            <div class="col-md-12">

if i click a tab with id two, i want to add active class on class="tab-pane".

4
  • use (".tab-pane").addClass("active") Commented Jan 18, 2016 at 8:46
  • bootstrap has that add active class for tab. Commented Jan 18, 2016 at 8:48
  • can you explain a full script implementation Commented Jan 18, 2016 at 8:48
  • If you use Bootstrap it should to that itself without having to do it from scratch. Maybe you're missing something. Have you included Bootstrap libraries correctly?! Commented Jan 18, 2016 at 8:49

2 Answers 2

3

This should work but boostrap already has it.

$(".tab-pane").click(function(){
      $(".tab-pane").removeClass("active"); //to remove active class from other tabs
      $("this").addClass("active"); //to add active class to clicked tab
    });
Sign up to request clarification or add additional context in comments.

1 Comment

thank it's work for me, but my problem is not done anymore i think i've wrong idea, anyway thank for the script it's work for me
0

You could use the click function.

$(".tab-pane").click(function(){
      $(".tab-pane").attr("class","tab-pane active"); //add whatever class you want to. In this case, `active`is added. 

    });

Comments

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.