• Settings
  • All geek questions in one place

    How to update url hash correctly when selecting jQuery tab?

    HTML:

    <div id="tabs"> <ul> <li><a href="#settings">Settings</a></li> <li><a href="#fields">Fields</a></li> </ul> <div id="settings"> //Tab Contents </div> <div id="fields"> //Tab Contents </div> </div> 

    How can I apply the functionality of jQueryUI Tab and make it update the URL hash when a new tab is selected?

    +6
    javascript html jquery-ui-tabs
    Kehlan Jul 25 '13 at 18:41
    source share
    2 answers

    In addition to updating the hash when changing tabs (with the beforeActivate event, as in shruggernaut's answer), it is very useful to update the active tab when changing the hash (i.e. include browser history, back / forward buttons and manual user input to the hash)

     $(window).on('hashchange', function () { if (!location.hash) { $('#tabs').tabs('option', 'active', 0); // activate first tab by default return; } $('#tabs > ul > li > a').each(function (index, a) { if ($(a).attr('href') == location.hash) { $('#tabs').tabs('option', 'active', index); } }); }); 
    +4
    Dejan milosevic Apr 2 '15 at 10:13
    source share

    Use this code to create jQuery user interface tabs:

     $('#tabs').tabs({ beforeActivate: function (event, ui) { window.location.hash = ui.newPanel.selector; } }); 

    I created this answer because I cannot find any with the modern method. Hope this helps someone else!

    +17
    Kehlan Jul 25 '13 at 18:41
    source share

    Source: https://habr.com/ru/post/950298/

    More articles:

    • Rails 4 - will_paginate - ruby-on-rails
    • What can I do to speed up this code (string similarity)? - c ++
    • When you scale the css3 element, what transition properties change? - css
    • Can I insert a large text value into SQL Server from ASP.net without having the entire file in memory on the web server? - c #
    • How to override Spring @Autowire annotation and set null field? - spring
    • knitr versus interactive behavior R - r
    • How to make sure that this process is NOT running, and exit the script if it is powershell
    • powershell: synchronous stop process - powershell
    • Python __call__ replication in javascript? - javascript
    • Role taxes in woocommerce - php

    All Articles

    Geek Questions | 2019