Note that there are some explanatory texts on larger screens.

plurals
  1. POAutomatically select Foundation 4 tab on page load
    primarykey
    data
    text
    <p>I'm using nested tabs in Foundation 4. When a user is redirected by the server to a specific anchor on the dashboard (for example, <code>#account-email</code>, after they've submitted the update email form), I want to load that section automatically instead of forcing them to click through to the sub-section again.</p> <p>The best idea I've come up with is to grab the anchor from <code>location.href</code> and iterate through the nested section anchors, clicking on each one as the user would have to do anyway. Although it's clicking on the correct elements, it just stays on the default tab (note I have the <code>one_up</code> option set to <code>false</code> already).</p> <p><strong>Why?</strong></p> <p>My jQuery:</p> <pre><code>$(document).ready( function() { $(document).foundation('section'); var match = /.+(#[\w-]+)$/.exec(location.href); if( match[1] ) { var anchors = match[1].split('-'); console.log(anchors); var click = ''; for( var i=0; i&lt;anchors.length; i++ ) { // concat each nested section click += ((i&gt;0) ? '-' : '') +anchors[i]; $('.title a[href="'+click+'"]').click(); console.log(click+': '+$('.title a[href="'+click+'"]').html()); } } }); // output: // ["#account", "email"] // #account: Account // #account-email: Email </code></pre> <p>And my (simplified) markup:</p> <pre><code>&lt;div data-section="auto" data-options="deep_linking: true; one_up: false;" class="section-container auto" style=""&gt; &lt;div class="section" style=""&gt; ...first top-level section... &lt;/div&gt; &lt;div class="section active"&gt; &lt;h2 data-section-title="" class="title"&gt;&lt;a href="#account"&gt;Account&lt;/a&gt;&lt;/h2&gt; &lt;div class="content"&gt; ...second top-level section: should be displayed for /dashboard#account... &lt;div data-section="auto" data-options="deep_linking: true; one_up: false;" class="section-container auto"&gt; &lt;div class="section active"&gt; &lt;h3 data-section-title="" class="title"&gt;&lt;a href="#account-email"&gt;Email&lt;/a&gt;&lt;/h3&gt; &lt;div data-section-content="" class="content"&gt; ...email sub-section: should be displayed for /dashboard#account-email... &lt;/div&gt; &lt;/div&gt; &lt;div class="section" style="padding-top: 0px;"&gt; &lt;h3 data-section-title="" class="title"&gt;&lt;a href="#account-password"&gt;Password&lt;/a&gt;&lt;/h3&gt; &lt;div data-section-content="" class="content"&gt; ...email sub-section: should be displayed for /dashboard#account-password... &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload