Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: jQuery Links

  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    123
    Thanks
    20
    Thanked 1 Time in 1 Post

    jQuery Links

    my javascript:
    Code:
    	<script type="text/javascript" charset="utf-8">
    function getHash() {
            var menu_item = window.location.hash;
            return menu_item.substring(1);
    }
    $(document).ready(function() {
            var menu_item = getHash();
            if (menu_item == null) {
                    var menu_item = 'content1';
            }
            var tabContainers = $('div#tabbed-menu > div');
            tabContainers.hide().filter('#' + menu_item).show();
            $('div#tabbed-menu ul#tabs a').removeClass('active');
            $('a#m_item_' + menu_item).addClass('active');
    
            $('div#tabbed-menu ul#tabs a').click(function() {
                    tabContainers.hide();
                    $('div#tabbed-menu ul#tabs a').removeClass('active');
                    $(this).hide();
                    $(this).addClass('active');
                    $(this).fadeIn(150);
                    tabContainers.filter(this.hash).fadeIn(150);
    
                    return false;
            }).filter('#' + menu_item).click();
    
    });
    	</script>


    HTML

    Code:
            <ul id="tabs">
              <li><a href="#content1" id="m_item_content1" title="Home" class=
              "menu"><span>Home</span></a></li>
    
              <li><a href="#content2" id="m_item_content2" title="Portfolio" class=
              "menu"><span>Portfolio</span></a></li>
    
              <li><a href="#content3" id="m_item_content3" title="Services" class=
              "menu"><span>Services</span></a></li>
            </ul>

    When I click the link, I want the #content1/#content2/#content3 to be appended to the URL, however jQuery stops this from happening. What can I do?

    Thanks

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You can make it do it yourself:

    Code:
    $('div#tabbed-menu ul#tabs a').click(function() {
        window.location.hash = this.href;
        ...
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • Users who have thanked A1ien51 for this post:

    cheechm (06-09-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •