Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's how I would do it:</p> <p>HTML:</p> <pre><code>&lt;form&gt; &lt;div id="q-1" class="question"&gt; &lt;p&gt;Question?&lt;/p&gt; &lt;input type="radio" name="answer-1" value="A" /&gt;A &lt;input type="radio" name="answer-1" value="B" /&gt;B &lt;input type="radio" name="answer-1" value="C" /&gt;C &lt;input type="radio" name="answer-1" value="D" /&gt;D &lt;p&gt;&lt;a href="#q-2"&gt;Next&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;div id="q-2" class="question"&gt; ... &lt;/div&gt; &lt;div id="q-3" class="question"&gt; ... &lt;/div&gt; &lt;/form&gt; </code></pre> <p>JS:</p> <pre><code>$('.question input[type="radio"]').click(function () { // checkAnswer(this.id, this.title); // You may want to add a title attribute and use this.parentNode.id instead // The code below randomly decides if it's true or false, FOR TESTING ONLY var check = Math.floor( Math.random() * 2 ); $(this).nextAll('p').prepend(check ? 'correct ' : 'incorrect ').fadeIn(); $(this).siblings('input[type="radio"]').addBack().prop('disabled', true); $(this).parent().next().find('input[type="radio"]').prop('disabled', false); }); </code></pre> <p>CSS:</p> <pre><code>.question p{display:none} .question p:first-child{display:block;} </code></pre> <p>I used a number of jQuery functions to keep the code as small as possible. Please see below for links to a few useful documentation pages:</p> <ul> <li><a href="http://api.jquery.com/nextAll" rel="nofollow"><code>.nextAll()</code></a></li> <li><a href="http://api.jquery.com/addBack/" rel="nofollow"><code>.addBack()</code></a></li> <li><a href="http://api.jquery.com/prop/" rel="nofollow"><code>.prop()</code></a></li> <li><a href="http://api.jquery.com/siblings/" rel="nofollow"><code>.siblings()</code></a></li> </ul> <p>Here's a working demo: <a href="http://jsfiddle.net/R9MCT/2/" rel="nofollow">http://jsfiddle.net/R9MCT/2/</a></p>
    singulars
    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.
 

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