Which method can be used to stop the event from propagating in the capturing or bubbling phase?
- event.stopPropagation()
- event.preventDefault()
- event.stopPropagationPhase()
- event.cancelPropagation()
The event.stopPropagation() method is used to stop the event from propagating further in the DOM tree. It prevents both capturing and bubbling phases, ensuring that the event doesn't trigger any other event listeners on the same element or its ancestors. This can be helpful in controlling event flow.
Loading...
Related Quiz
- Which method removes the last element from an array and returns that element?
- In which scenario is a function expression preferred over a function declaration?
- JavaScript was initially designed to make web pages more _________.
- The arithmetic operator _______ increments the value of a variable by 1.
- The mechanism of closing over variables is a core concept in ________ programming in JavaScript.