1

I want to add class active for the div having class in (contained in div with class shiftTabs).

I used below jQuery but not working.

$('.shiftTabs .tab-pane[class="in"]').not('.active').addClass('active');

Html:-

 <div class="shiftTabs">
      <div class="tab-pane fade in" id="tab1" tabindex="1">
      <div class="tab-pane fade" id="tab2" tabindex="2">
      <div class="tab-pane fade" id="tab3" tabindex="3">
    </div>
2
  • Why do you want to add extra class to active element. You can use in class and add properties on it. Commented Jan 22, 2018 at 6:51
  • i want to add in particular class Commented Jan 22, 2018 at 6:52

2 Answers 2

0

You need to chain the class selector instead of using attribute equals selector:

$('.shiftTabs .tab-pane.in:not(.active)').addClass('active');
Sign up to request clarification or add additional context in comments.

Comments

0
  1. Just use the selector $('.shiftTabs .tab-pane.in').not('.active')

$('.shiftTabs .tab-pane.in').not('.active').addClass('active');
.active {
  color: red
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="shiftTabs">
  <div class="tab-pane fade in" id="tab1" tabindex="1">123</div>
  <div class="tab-pane fade" id="tab2" tabindex="2">123</div>
  <div class="tab-pane fade" id="tab3" tabindex="3">123</div>
</div>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.