0

I use jquery tabs plugin to make an element of several tabs. Each tab has an accordion (jquery accordion plugin).

<div id="tabs" class="faq-tabs">
<ul>
    <li><a href="#tabs-1">1</a></li>
    <li><a href="#tabs-2">2</a></li>
</ul>
<div id="tabs-1">
    <div id="accordion-1" class="accordion a-faq">
        <h3>Title 1</h3>
        <div>Block1</div>

        <h3>Titl2</h3>
        <div>Block2</div>
    </div>
</div>
<div id="tabs-2">
    <div id="accordion-2" class="accordion a-faq">
        <h3>Title 1</h3>
        <div>Block1</div>

        <h3>Titl2</h3>
        <div>Block2</div>
    </div>
</div>

In js code I activate tabs and accordion plugins that way:

$(function() {
    $( "#tabs" ).tabs();
    $( "#accordion-1,#accordion-2" ).accordion();
});

The problem is that #accordion-2 on second tab doesn't work. It seems that js code for binding accordion plugin is not correct.

Any advice, please? Thanks.

Anastasia S
  • 149
  • 2
  • 13

1 Answers1

2

Here is a working example, based on your code.

Check if you see any javascript errors in your console, as it should work fine.

$(function() {
  $( "#accordion-1,#accordion-2" ).accordion();
  $( "#tabs" ).tabs();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div id="tabs" class="faq-tabs">
  <ul>
    <li><a href="#tabs-1">1</a></li>
    <li><a href="#tabs-2">2</a></li>
  </ul>
  <div id="tabs-1">
    <div id="accordion-1" class="accordion a-faq">
      <h3>accordion-1 Title 1</h3>
      <div>Block1</div>

      <h3>accordion-1 Titl2</h3>
      <div>Block2</div>
    </div>
  </div>
  <div id="tabs-2">
    <div id="accordion-2" class="accordion a-faq">
      <h3>accordion-2 Title 1</h3>
      <div>Block1</div>

      <h3>accordion-2 Titl2</h3>
      <div>Block2</div>
    </div>
  </div>
</div>

update

To make sure that the inner-accordions will work inside the different tabs you need to first make sure you init the .accordion() and only after that - init the .tabs()

$( "#accordion-1,#accordion-2" ).accordion();
$( "#tabs" ).tabs();
Dekel
  • 60,707
  • 10
  • 101
  • 129
  • It works, but not as expected. You see, first panel of accordion element on second tab is closed. – Anastasia S Dec 30 '16 at 10:29
  • Check the update on my answer :) next time you should make the question clear regarding what exactly is the problem. – Dekel Dec 30 '16 at 18:07