Solved

Loading a page into the tab, and selecting the correct tab?

Posted on 2011-09-02
6
224 Views
Last Modified: 2013-12-10
I have a page which contains JQuery tabs (taken straight from the Jquery API)

My JQuery function:
 
$(function(){

                // Tabs                
                $('#tabs').tabs({
                    select: function(event, ui) {
        
                        var url = $.data(ui.tab, 'load.tabs');
                        if( url ) {
                            location.href = url;
                            return false;
                        }
                        return true;
                    }
                });
               
            });

Open in new window


My Page
<div id="tabs">
                    <ul>
                        <li><a href="index.xhtml">Home</a></li>
                        <li><a href="#tabs-1">Products</a></li>
                        <li><a href="latest.xhtml">Latest</a></li>
                    </ul>
                    <div id="tabs-1">
.... This tabs contents....
</div>
</div>

Open in new window


The problem I am having is that when I click a tab it loads the page but the 1st tab is always selected.

How do I set the index based on the page I've selected

Thanks
0
Comment
Question by:directxBOB
  • 2
6 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36479039
double check you have the right number of end tag (or start)

<div>
</div>
</div>

0
 

Author Comment

by:directxBOB
ID: 36481214
I've double checked them in all files.
0
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 total points
ID: 36481939
have you tried with cookie persistence?  That way when the page reloads the tab is remembered

http://jqueryui.com/demos/tabs/#cookie
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 36481954
see here for a working version: http://jsfiddle.net/rjurd/KWDsK/

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question