Note that there are some explanatory texts on larger screens.

plurals
  1. POOnly first button with ID responds
    primarykey
    data
    text
    <p>For an assignment i have to make a page that has 3 questions with each 3 answers in the form of a button. When the button is clicked, the color of it will change depending if the answer is correct or not.</p> <p>I can get the Jquery to work, but it only seems to apply to the first correct and wrong button i have.</p> <p>like, the first correct answer is 1A, it will change, but no other correct answer will respond, even if they are clicked first, same for the wrong answers, only 1B will react.</p> <p>Question 1 answer 1A answer 1B answer 1C</p> <p>Question 2 answer 2A answer 2B answer 2C</p> <p>Question 3 answer 3A answer 3B answer 3C</p> <p>-edit- Ok i get it, cant re-use ID's..</p> <p>HTML</p> <h2>Doe mee aan onze quiz!</h2> <pre><code> &lt;h4&gt;Wat is de naam van Master Chief?&lt;/h4&gt; &lt;button class="buttons" id="buttonjuist"&gt;John-117&lt;/button&gt; &lt;button class="buttons" id="buttonfout"&gt;Douglas-092&lt;/button&gt; &lt;button class="buttons" id="buttonfout"&gt;James-016&lt;/button&gt; &lt;h4&gt;Hoeveel kandidaten zijn er voor het SPartan-II project?&lt;/h4&gt; &lt;button class="buttons" id="buttonfout"&gt;300&lt;/button&gt; &lt;button class="buttons" id="buttonjuist"&gt;150&lt;/button&gt; &lt;button class="buttons" id="buttonfout"&gt;75&lt;/button&gt; &lt;h4&gt;Waar wordt Master Chief gevonden?&lt;/h4&gt; &lt;button class="buttons" id="buttonfout"&gt;Reach&lt;/button&gt; &lt;button class="buttons" id="buttonfout"&gt;Harvest&lt;/button&gt; &lt;button class="buttons" id="buttonjuist"&gt;Eridanus&lt;/button&gt; </code></pre> <p>CSS</p> <pre><code>.buttons{ font-weight:bold; font-size:small; background-color:blue; width:200px; } </code></pre> <p>Jquery</p> <pre><code>$("#buttonjuist").on('click', function() { $(this).css({'background-color': 'green'}); }); $("#buttonfout").on('click', function() { $(this).css({'background-color': 'red'}); }); </code></pre>
    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