The whole idea is for the user to follow the "script" and click only on certain blocks, and when they click on the wrong pop-up Try again popup.

Exceptions:
$('.tabs li') - the name of the tabs (at the top of the screen)
$('.can-click') - blocks by which you can click (randomly on all tabs)
$('.table') - table of cells

Optional:
$('.try-again') - pop again Try again

Task:
Everything seems to work: when I click on the exception blocks, nothing happens, but when I first push past the same way, nothing (as far as I understand it is due to $(document).bind('click.body', function(e) only been applied and has not yet had time to work, but then when I want to click back on an exception, it shows Try again. I understand what the problem is, but I can’t fix it - I have no experience.

Screen tabs and tables

 $(document).bind('click.exclusion', function(e) { if ($(e.target).closest($('.tabs li')).length != 0 && $(e.target).closest($('.can-click')).length != 0) { e.preventDefault(); e.stopPropagation(); } else { $(document).bind('click.body', function(e) { if ($(e.target).closest($('.table')).length == 0) { e.preventDefault(); e.stopPropagation(); $('.try-again').show(); setTimeout(function(){ $('.try-again').hide() },1000); } else { $(document).unbind('click.body'); $(document).bind('click.myEvent', function(e) { if ($(e.target).closest($('.find')).length == 0) { e.preventDefault(); $('.try-again').show(); setTimeout(function(){ $('.try-again').hide() },1000); } else { $($('.find')).show(); $(document).unbind('click.myEvent'); $(document).bind('click.myEventReplace', function(e) { if ($(e.target).closest($('#find-replace')).length == 0) { e.preventDefault(); $('.try-again').show(); setTimeout(function(){ $('.try-again').hide() },1000); } else { $($('#find-replace')).show(); $(document).unbind('click.myEventReplace'); $(document).bind('click.myEventReplaceWhat', function(e) { if ($(e.target).closest($('#replace-what')).length == 0) { e.preventDefault(); $('.try-again').show(); setTimeout(function(){ $('.try-again').hide() },1000); } else { $($('#find-replace')).show(); $(document).unbind('click.myEventReplaceWhat'); $(document).bind('click.myReplaceAll', function(e) { if ($(e.target).closest($('.replace-all')).length == 0) { e.preventDefault(); $('.try-again').show(); setTimeout(function(){ $('.try-again').hide() },1000); } else { if ($('#replace-what').val() === 'n/a' || $('#replace-what').val() === 'N/A') { $(document).unbind('click.myReplaceAll'); var numberEnd = window.storage.endCell.slice(9,window.storage.endCell.length); var numberStart = window.storage.startCell.slice(1,window.storage.startCell.length); var endFor = Number(numberEnd)+1; for (var i = numberStart; i < endFor; i++) { if ($('#sheet1__'+window.storage.startCell.slice(0,1)+i).text() == $('#find-what').val()) { $('#sheet1__'+window.storage.startCell.slice(0,1)+i).html('<div>'+$('#replace-what').val()+'</div>'); } } $('.done').show(); setTimeout(function(){ $('.done').hide() },2000); } else { $('.try-again').show(); setTimeout(function(){ $('.try-again').hide() },1000); } } }); } }); } }); } }); } }); } }); 

    1 answer 1

    Look here

     $(document).click(function(e) { alert('try again'); }); $('.can-click, .tabs li, .table').click(function(e) { e.stopPropagation(); }) 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul class="tabs"> <li>tab1</li> <li>tab2</li> </ul> <div class="can-click">can-click</div> <table class="table"> <tr> <td>.table</td> </tr> </table> 

    • My popup is displayed, not an alert - Artem Holinka
    • one
      Not the point ... this is an example of the fact that the event does not apply to these selectors. Instead of an alert, insert $ ('. Try-again'). Show (); - sepgg
    • thank. did not have to bother with bind'ami. as always the answer is in one line))) - Artem Holinka