Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Can you test this code:</p> <pre><code>$(document).ready(function () { var p1=0, p2=0; $('#cheap').text(p1 + ' Standard seats= £' + (p1*10)); $('#premium').text(p2 + ' Premium seats= £' + (p2*20)); $('td img').click(function () { if ($(this).parent().hasClass('x')) { alert("Seat " + ($(this).parent().attr("id")) + " is taken"); } else if ($(this).parent().hasClass('selected')){ $(this).attr('src', 'images/a.gif'); $(this).parent().removeClass('selected'); var z = $(this).parent().attr('id'); if ($(this).parent().hasClass('n')){ p1--; } else if ($(this).parent().hasClass('p')){ p2--; } $('#'+z+'1').remove(); } else { if ($(this).parent().hasClass('n')){ p1++; } else if ($(this).parent().hasClass('p')){ p2++; } $(this).attr('src', 'images/c.gif'); $(this).parent().addClass('selected'); alert($(this).parent().attr("class")); var z = $(this).parent().attr('id'); $('#order').append('&lt;p id="'+z+'1"&gt;'+z+'&lt;/p&gt;'); }; $('#cheap').text(p1 + ' Standard seats= £' + (p1*10)); $('#premium').text(p2 + ' Premium seats= £' + (p2*20)); return false; }); }); </code></pre> <p>Edit: A had some global variables to save the number (cheap and premium) of seat selected.</p> <p>A move </p> <pre><code>$('#cheap').text(p1 + ' Standard seats= £' + (p1*10)); $('#premium').text(p2 + ' Premium seats= £' + (p2*20)); </code></pre> <p>in the click event</p> <p>and a had this when a seat is unselected:</p> <pre><code>if ($(this).parent().hasClass('n')){ p1--; } else if ($(this).parent().hasClass('p')){ p2--; } </code></pre> <p><strong>Edit 2:</strong> interactive code: </p> <p><a href="http://jsfiddle.net/kdQmq/3/" rel="nofollow">http://jsfiddle.net/kdQmq/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