On the phone, some element overlaps the blocks and there is no possibility to find out, since there is no firebug , etc. How can I make jQuery so that when I click into an area, it will show me an alert'ом the topmost element at this point?

    1 answer 1

    It is done like this. The key is e.stopPropagation();

     $('div').on('click', function(e){ $(e.target).css('background', 'red'); alert($(e.target).attr('class')); e.stopPropagation(); }); 
     div { border: 1px solid black; padding: 30px; } 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> Первый <div class="first"> Второй <div class="second"> Третий <div class="third"></div> </div> </div> 

    • you should not always hide the snippet :-) usually minimization should be added when there is a lot of code, or when there are several. In this case, it is better to leave it open so that the solution is immediately visible - Grundy
    • @Grundy okey, there is such a thought. - Jean-Claude