How can I directly link to a specific JavaScript tab?

My site has a tabbed interface that is used sequentially on all pages. I can link to the base page (first tab), but I can’t figure out how to link it to a specific tab.

This is my JavaScript:

$(document).ready(function() {
  $(".tabs a").click(function() {
    var $this = $(this);
    $(".panel").hide();
    $(".tabs a.active").removeClass("active");
    $this.addClass("active").blur();
    var panel = $this.attr("href");
    $(panel).fadeIn(250);
    return false;
  });
$(".tabs li:first-of-type a").click();
});

And each of my pages is configured as follows:

<div id="aboutContainer">
    <ul class="tabs">
        <li><a href="#panel1">About Us</a></li>
        <li><a href="#panel2">Contact Us</a></li>
        <li><a href="#panel3">Mailing List</a></li>
        <li><a href="#panel4">Terms</a></li>
        <li><a href="#panel5">Privacy Policy</a></li>
        <li><a href="#panel6">Help</a></li>
    </ul>
        <div class="panelContainer">
            <div class="panel" id="panel1">
                <?php include('includes/aboutme.php'); ?>
            </div>

            <div class="panel" id="panel2">
                <?php include('includes/contact.php'); ?>
            </div>

            <div class="panel" id="panel3">
                <?php include('includes/mailinglist.php'); ?>
            </div>

            <div class="panel" id="panel4">
                <?php include('includes/terms.php'); ?>             
            </div>

            <div class="panel" id="panel5">
                <?php include('includes/privacypolicy.php'); ?>
            </div>

            <div class="panel" id="panel6">
                <?php include('includes/cheekyreference.php'); ?>
            </div>
        </div>
</div>

Any pointers would be greatly appreciated. I am new to JavaScript and could not find the answer on the Internet.

To clarify the situation a bit:

about.php, . , , : , , . , , ​​ " " "", , .

+3
4

"", , :

$(".tabs a[href='#panel14']").click();

+1

- - URL-. :

about.php # panel1

, , hashbang:

about.php #! Panel1

( - , SEO.)

script, - URL-, .

, , . , .

jQuery :

$(".tabs a[href="+window.location.hash+"]").click();

: , , .

+1
$('a[href="#panel1"]').click(function() {
        //insert action here;
});​
0

, , .

"", URL- , tab1 ( ).

jQuery JavaScript

http://jsrouter.codeplex.com/

There are, of course, other routing solutions, there is a link to the postflowflow column on the javascript clientide routing / pathing library topic

0
source

All Articles