Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Interview Questions Folder #154

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added Interview Questions Folder
  • Loading branch information
SivaNagaKalyan committed Aug 9, 2022
commit f1c7e30c2e625dd8c6b7da40e44b4cd3584dd8d6
31 changes: 31 additions & 0 deletions InterviewQuestions/EventBubbling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Event Bubbling and Capturing
//when you have a nested elements in the dom and when you add a event to the last child it will follow pattern
// as that child to till the parent
// whereas in capturing the process is reverse

// The process of propagating from nearest element to farthest element in the dom is called "EVENT BUBBLING"
// The process of propagating from farthest element to nearest element in the dom is called "EVENT CAPTURING"
// EVENT CAPTURING is also called as "TRICKLING"
// stopPropagation() will stop the propagation either in event bubbling or in event capturing.


const grandParent = document.getElementById('grand-parent');
const parent = document.getElementById('parent');
const child = document.getElementById('child');


grandParent.addEventListener('click',() => {
console.log("Grand-Parent")
},true)
// The true argument refers to the event capturing and true says that implement capturing.

parent.addEventListener('click',() => {
console.log("parent")
},true)

child.addEventListener('click',() => {
console.log("child")
},true)

// In the above example in the case of false argument the event bubbling will occur and if you click on
//child div all the three log statements will appear because of the effect of event bubbling