How does the click () function in jquery work when working with multiple glass divs?

How does the click () function in jquery work with multiple glass divs?

I have one main div and another div inside the main div, when I click on the div inside, it is also considered a click on the main div, but I do not want this, I want it to consider only clicking on the inside of the div.

<div id="main"><div id="inner"></div></div>

Let's say that the main div is much larger and the inner one is just a small square when I click on the inner div (small square). I do not want it to run anyting, as if I were clicking on the main div, How do I maneuver? Thanks again!

+3
source share
2 answers

, , . , , .

, event.stopPropagation(), -.

$('#inner').click(function(evt) {
    evt.stopPropagation();
    // your code
});

return false; .

$('#inner').click(function(evt) {
    // your code
    return false;
});

: http://jsfiddle.net/ZpeYr/

+5
$('#inner').click(function() {  
  alert('clicked inner div'); // do something
});

div, css.

0

Source: https://habr.com/ru/post/1752558/


All Articles