Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From what I understood of the problem, this requires a few things to be in place to make this work.</p> <p>Some pre-condition changes to your existing HTML for the following JS code to work, I added IDs to the list items.</p> <pre><code>&lt;ul class="nav"&gt; &lt;li id="nav-step1"&gt;&lt;a href="#step1"&gt;&lt;span&gt;1&lt;/span&gt; ONE&lt;/a&gt;&lt;/li&gt; &lt;li id="nav-step2"&gt;&lt;a href="#step2"&gt;&lt;span&gt;2&lt;/span&gt; TWO&lt;/a&gt;&lt;/li&gt; &lt;li id="nav-step3"&gt;&lt;a href="#step3"&gt;&lt;span&gt;3&lt;/span&gt; THREE&lt;/a&gt;&lt;/li&gt; &lt;li id="nav-step4"&gt;&lt;a href="#step4"&gt;&lt;span&gt;4&lt;/span&gt; FOUR &lt;/a&gt;&lt;/li&gt; &lt;li id="nav-step5"&gt;&lt;a href="#step5"&gt;&lt;span&gt;5&lt;/span&gt; FIVE&lt;/a&gt;&lt;/li&gt; &lt;li id="nav-step6"&gt;&lt;a href="#step6"&gt;&lt;span&gt;6&lt;/span&gt; SIX&lt;/a&gt;&lt;/li&gt; &lt;li id="nav-step7"&gt;&lt;a href="#step7"&gt;&lt;span&gt;7&lt;/span&gt; SEVEN&lt;/a&gt;&lt;/li&gt; &lt;li id="nav-step8"&gt;&lt;a href="#step8"&gt;&lt;span&gt;8&lt;/span&gt; EIGHT&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>And some pre-condition additions to your CSS, I added a disabled class to differentiate the states visually.</p> <pre><code>#csp-wrap ul.nav li.disabled a, #csp-wrap ul.nav li.active a { cursor: default; } #csp-wrap .disabled { filter: alpha(opacity=50); opacity: .5; } </code></pre> <p>First you will want to set up an initial state where all of the list items are disabled except for the first one, and all of the next buttons are disabled</p> <pre><code>// get all list items var listItems = $("ul.nav li"); // disable all list items listItems.addClass('disabled'); // enable the first list item listItems.first().removeClass('disabled'); // disable all next buttons $('.next').prop('disabled', true); </code></pre> <p>Set up a click handler for the execute button that enables the associated next button.</p> <pre><code>// execute click handler $('.execute').click(function(event) { // Get the associated next button $(this).siblings('.next').prop('disabled', false); }); </code></pre> <p>Create a click handler for the next button to handle moving on to the next step.</p> <pre><code>// next click handler $('.next').click(function(event) { // get the associated nav item var navId = '#nav-' + $(this).parents('.nav-content').attr('id'); // enable the next list item $(navId).next().removeClass('disabled'); // trigger click on the next list item to step to it $(navId).next().trigger('click'); }); </code></pre> <p>Lastly, modify the onclick event to not consider the active or any disabled list items.</p> <pre><code>// onclick event $("ul.nav").on({ click: function () { $("ul.nav li").removeClass("active"); $(this).addClass("active"); $(".nav-content").hide(); var activenav = $(this).find("a").attr("href"); $(activenav).show(); return false; } }, 'li:not(.disabled,.active)'); </code></pre> <p>You can try it out in the forked fiddle here: <a href="http://jsfiddle.net/UZwqx/3/" rel="nofollow">http://jsfiddle.net/UZwqx/3/</a></p>
 

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