1

I have a set of tabs, when a class is active I want to add the following:

<hr class="break-sec">

This class has to be inside the span class and after the title-text class as shown below. Here is the code and where it has to be inserted.

<li class="vc_tta-tab vc_active" data-vc-tab="">
  <a href="#1485520583544" data-vc-tabs="" data-vc-container=".vc_tta">
    <span class="vc_tta-title-text">
      GALLERY 
      <hr class="break-sec">
    </span>
  </a>
</li>

How can I accomplish this using jQuery?

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
user1673498
  • 431
  • 1
  • 8
  • 26

3 Answers3

3

Is this what you are thinking about?

$('.vc_tta-title-text').append('<hr class="break-sec">') Will insert the hr right after the Span text

$('.vc_active .vc_tta-title-text').append('<hr class="break-sec">')

$('.vc_tta-tab').click(function() {
$('.vc_active .vc_tta-title-text').find("hr").remove();
  $('.vc_active').removeClass("vc_active");
  $(this).addClass("vc_active");
  $('.vc_active .vc_tta-title-text').append('<hr class="break-sec">')
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li class="vc_tta-tab" data-vc-tab="">
  <a href="#1485520583544" data-vc-tabs="" data-vc-container=".vc_tta">
    <span class="vc_tta-title-text">GALLERY 
</span></a>
</li>

<li class="vc_tta-tab vc_active" data-vc-tab="">
  <a href="#1485520583544" data-vc-tabs="" data-vc-container=".vc_tta">
    <span class="vc_tta-title-text">PAGES 
</span></a>
</li>

<li class="vc_tta-tab" data-vc-tab="">
  <a href="#1485520583544" data-vc-tabs="" data-vc-container=".vc_tta">
    <span class="vc_tta-title-text">VIDEOS 
</span></a>
</li>
Carsten Løvbo Andersen
  • 26,637
  • 10
  • 47
  • 77
2

You could use append to span/.vc_tta-title-text based on the active li vc_active like :

$('.vc_active .vc_tta-title-text').append('<hr class="break-sec">');
//OR
$('.vc_active span').append('<hr class="break-sec">');

Add click event to make it append the hr dynamically :

$('body').on('click', '.vc_tta-tab', function(){
    $('.vc_tta-title-text hr').remove(); //remove 'hr' from previous active tab
    $('.vc_active span').append('<hr class="break-sec">'); //Add 'hr' to the new active tab
})

Hope this helps.

$('.vc_active .vc_tta-title-text').append('<hr class="break-sec">');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<ul>
<li class="vc_tta-tab" data-vc-tab="">
<a href="#1485520583544" data-vc-tabs="" data-vc-container=".vc_tta">
  <span class="vc_tta-title-text">
    NOT ACTIVE
  </span>
</a>
</li>

<li class="vc_tta-tab vc_active" data-vc-tab="">
<a href="#1485520583544" data-vc-tabs="" data-vc-container=".vc_tta">
  <span class="vc_tta-title-text">
    ACTIVE
  </span>
</a>
</li>

<li class="vc_tta-tab" data-vc-tab="">
<a href="#1485520583544" data-vc-tabs="" data-vc-container=".vc_tta">
  <span class="vc_tta-title-text">
    NOT ACTIVE
  </span>
</a>
</li>
<ul>
Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
0

Mixed content is always a little more complicated, but append should do it:

$('span.vc_tta-title-text').append($('<hr class="break-sec">'));

(Putting the new content in a jQuery object converts it to DOM elements.)

Richard
  • 106,783
  • 21
  • 203
  • 265