javascript - Check if elements clicked in a specific order -
i beginner on javascript , need test children. have 3 square , need check , display if clicked in specific order, defined "order" property. validation of click displayed on corresponding span element status-1 click no. 1, status-2 click no. 2 , status-3 click no. 3 html code
<div class="square blue" order="3"> </div> <div class="square yellow" order="2"> </div> <div class="square red" order="1"> </div> <br class="clearboth" /> <span id="status-1"></span> <span id="status-2"></span> <span id="status-3"></span>
i got stuck @ click validation
$('.square').on('click',function(){ // check if click ok or not , display }
thank help
use this
var click_numbers = 0; $('.square').on('click',function(){ click_numbers ++; if (click_numbers == $(this).attr('order')){ $('#status-'+click_numbers).html('ok'); } else { $('#status-'+click_numbers).html('not ok'); } if (click_numbers === 3){ click_numbers=0; } });
Comments
Post a Comment