Last active
August 5, 2016 15:34
-
-
Save swapnilshrikhande/e828dd01ae883fca8cc16cf9da05b963 to your computer and use it in GitHub Desktop.
How event bubbling works ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .parent{ | |
| min-height: 400px; | |
| min-width : 400px; | |
| background-color:yellow; | |
| } | |
| .parent .son{ | |
| min-height: 100px; | |
| min-width : 100px; | |
| background-color:red; | |
| } | |
| .parent .daughter{ | |
| margin-top : 100px; | |
| min-height: 100px; | |
| min-width : 100px; | |
| background-color:green; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="parent"> | |
| <div class="child son"> | |
| </div> | |
| <div class="child daughter"> | |
| </div> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function(event){ | |
| $(".parent").on("click",".son",function(event){ | |
| console.log("event.target",event.target); | |
| console.log("this",this); | |
| }); | |
| $(".parent").on("click",function(event){ | |
| if( event.target === this ){ | |
| console.log("Event directly on parent"); | |
| } | |
| console.log("event.target",event.target); | |
| console.log("this",this); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment