2

New to this forum so please be gentle! I have been having issues with jQuery Accordions which are inside a set of tabs. The tabs work fine and so does the Accordion, but... what I really would like is to be able to use a link from within part of the Accordion to go to another part of the Accordion. The Accordion will be used as an instruction manual so therefore in certain sections there will be a bit that basically says to the user to "see this section".

I have checked on here at certain answers such as: jquery ui accordions within tabs and http://jsfiddle.net/9nKZp/1/show/#1| and have checked all over the internet searching for Accordions with anchors as well as Nested Accordions in tabs but I have YET to come across this being done!! Can't really believe that no one has done this!

Here is the code I have so far:

<!-- tabs -->
<link rel="stylesheet" href="/resources/css/tabs.css" type="text/css" media="screen" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="/resources/js/tabs.js"></script>
<!-- ENDS tabs -->
<!-- accordion -->
<link rel="stylesheet" href="/resources/css/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<!-- ENDS accordion -->

<script>
    $(function () {
        $(".accordion").accordion({
            collapsible: true,
            heightStyle: "content",
            active: false,
        
        });
    });
</script>

<!-- TABS START -->
<div class="tabs_wrapper">
    <!-- 1st new tab design START -->
    <div id="new_tabs">
        <ul>
            <li class="active"><a href="#tab1" rel="tab1">Tab1</a></li>
            <li><a href="#tab2" rel="tab2">Tab2</a></li>
            <li><a href="#tab3" rel="tab3">Tab3</a></li>

        </ul>
    </div>
    <div id="new_tabs_content">
        <div id="tab1" class="tab_content" style="display: block;">

            <p>
                Data on first tab
            </p>


        </div>
        <div id="tab2" class="tab_content">
            <h1>Tab2</h1>

            <div class="accordion">

                <h3><a id="#1">1</a></h3>
                <div>
                    Content of 1
                    <div class="accordion">
                        <h3><a id="#1.1">1.1</a></h3>
                        <div>
                            Content of 1.1
                            <div class="accordion">
                                <h3><a id="#1.1.1">1.1.1</a></h3>
                                <div>
                                    Content of 1.1.1, please see <a href="#2.1.2">2.1.2</a>
                                </div>
                                <h3><a id="#1.1.2">1.1.2</a></h3>
                                <div>
                                    Content of 1.1.2
                                </div>
                                <h3><a id="#1.1.3">1.1.3</a></h3>
                                <div>
                                    Content of 1.1.3
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <h3><a id="#2">2</a></h3>
                <div>
                    Content of 2
                    <div class="accordion">
                        <h3><a id="#2.1.1">2.1.1</a></h3>
                        <div>
                            Content of 2.1.1
                        </div>
                        <h3><a id="#2.1.2">2.1.2</a></h3>
                        <div>
                            Content of 2.1.2
                        </div>
                        <h3><a id="#2.1.3">2.1.3</a></h3>
                        <div>
                            Content of 2.1.3
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <div id="tab3" class="tab_content">
            <h1>Tab3</h1>
            <p>another load of data</p>
        </div>

    </div>
    <!-- 1st new tab design END -->
</div>
<!-- TABS END -->

Please let me know if you require any further code that I am using such as the tabs.js etc.

Please help me! Is this at all possible?!

Many thanks and big hugs if you can help!!:-)

Amir
  • 1,328
  • 2
  • 13
  • 27
Chrissy
  • 21
  • 2
  • The 2nd link seems to work on my end. What else you need? (Probably you are trying to use different tabs plugin - /resources/js/tabs.js ?) – Minister Jan 21 '14 at 15:57
  • As per my query in my first paragraph above: what I really would like is to be able to use a link from within part of the Accordion to go to another part of the Accordion. The Accordion will be used as an instruction manual so therefore in certain sections there will be a bit that basically says to the user to "see this section". In the code i have pasted in section 1.1.1 there is a "please see" link which needs to then send the user to section 2.1.1 of the accordion. The tabs and accordion work fine but i cannot make the links within the accordion to go to different sections work. – Chrissy Jan 21 '14 at 16:02
  • OK, check the example here: http://jsfiddle.net/9nKZp/1/show/#1|1 (opens 2nd tab, 2nd question, but it seems doesn't work for Q1) and http://jsfiddle.net/9nKZp/1/show/#2|1 (opens 3rd tab and 2nd question). If that works as needed, then you may want to provide a JSfiddle example of your code and we'll experiment further until we cover the Q1 problem and other requirements (if there are other). :-) – Minister Jan 21 '14 at 16:07
  • 1
    Thanks Minister but I dont think I am making myself clear. I need the link within the SAME page not an external link in the address bar to navigate to a certain section in the accordion. I am not looking at using the address bar from an external link just an internal link to another accordion section. – Chrissy Jan 21 '14 at 16:11
  • Now it's clearer (it would be best to update your question)! It seems you'll need a specific JS functionality, so if you put your code in a demo site like http://jsfiddle.net, then more people will have a try and you'll have better chances to find a working solution. ;-) – Minister Jan 21 '14 at 16:16
  • OK heres the jsfiddle: http://jsfiddle.net/chrissy/6apBa/ if you navigate to tab 2 then expand the accordion to 1.1.1 you will see a link inside that section to send the user to section 2.1.2. I just cant seem to get the link to set the focus on 2.1.2 and open that particular section.... :-( – Chrissy Jan 21 '14 at 16:30
  • I like these tabs and if you have any progress, I'll try to help further when I have some extra time... If you follow my idea, you can post comments under my answer, otherwise you can post it here (under the question). – Minister Jan 22 '14 at 18:00

1 Answers1

1

Here is the idea of how to get this one to work.

In the example http://jsfiddle.net/9nKZp/1/show/#1|1 it seems like the tabs linking works, but it only works when you load the page in a new tab, not from link.

You need your own jsfiddle (you already have one v.1), where you should place some example content WITH links from one tab/question to another pair tab/question (or there may have links to the same tab, but another question)! You also should implement the code from the semi-working example to your code.

Then the logic is as follows (examples using jQuery):

(1) Create on click event for each link you place inside the tabs, something like that:

$('#all_tabs_container a').click( function(){
    checkInternalLinks();
});

In the function checkInternalLinks()...:

(2) You should check if the link is internal (#...) and if it is in a know format (like: #x|x or #x|x|x or both)

(3) When you validate this link you'll need to make the specific functionality to switch tabs and accordeons.

(4) The needed functionality already exists(!), but on page load, so you'll need to take some time on it and realize what is hapenning, so you can copy the same code to the onclick event function.

If you like the idea, you can start! Even if you can't complete it, I'm sure someone else will help :-)

Minister
  • 1,198
  • 2
  • 10
  • 18
  • Whoopppp!!!! Finally solved it... with the help of my genius other half!!! See this fiddle: http://jsfiddle.net/chrissy/3hL3N/2/ this also works if you use hash tags in your url such as www.website.com#instructions_2_3 this will take you to the instruction tab and accordion item 2.3! My life is complete! – Chrissy Jan 29 '14 at 17:14
  • I just checked it for 3 minutes and it seems the only missing functionality is the setting of the hash in the address bar. In the first example there are multiple nested tabs and all of them was linkable (each level), now in your example the internal links works, but the address bar shows links to first level only! So if you want to send the link by email or post it here, I won't be able to find the correct tab! I'll try to look deeply into this in the next few days... – Minister Jan 30 '14 at 07:21