Link directly to jquery tab and display content

Discussion in 'JavaScript' started by Kinda Intellectual, Dec 7, 2012.

  1. #1
    First off I'm not very experienced with javascript/jquery or anything beyond basic html. I'm trying to create links to a set of tabs and so far I've been able to create anchor links, but once the links (a href and a name) are clicked on it doesn't display that tab just the default (1st tab).

    I found this script (below) in the .js file, in reference to the tabbed area, what is it I need to modify to get the anchor links to work.

    /**************************************************************************
    ******************           Tabbed Area          ********************
    ***************************************************************************/
    $(document).ready(function() {
    
    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content
    
    //On Click Event
    $("ul.tabs li").click(function() {
    
    $("ul.tabs li").removeClass("active"); //Remove any "active" class
    $(this).addClass("active"); //Add "active" class to selected tab
    $(".tab_content").hide(); //Hide all tab content
    
    var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to     identify the active tab + content
    $(activeTab).fadeIn(); //Fade in the active ID content
    return false;
    });
    Code (markup):
    Thanks for any and all help. If you need to see a demo of the page or the html code of it heres a link to the demo page: http://themeforest.net/item/electron-responsive-landing-page/full_screen_preview/2607118
    (Yes I asked for help from the developer but he said it wasn't possible, but when searching up the topic it does seem to be possible, so I came here)

    Again thanks!

    Edit: I found and tried this:
    var $tabs = $('#example').tabs(); // first tab selected
    
    $('#my-text-link').click(function() { // bind click event to link
        $tabs.tabs('select', 2); // switch to third tab
        return false;
    });
    
    Code (markup):
    but I can't get it to work with my links. Each tab link looks like this:

    <ul class="tabs">
    
    <li><a href="#tab1" name="LearnMore">How it Works</a></li>
    <li><a href="#tab2">F.A.Q</a></li>
    <li><a href="#tab3" name="UnlockNow">Unlock Now</a></li>
    
    </ul>
    Code (markup):
    But using the href or the name attribute doesn't work for the above js code. What am I doing wrong?
     
    Kinda Intellectual, Dec 7, 2012 IP