In a UI with nested dropdown menus, a developer wants to ensure that clicking a nested menu item does not trigger the click event of its parent menu. What method can be used to stop the event from reaching the parent menu?
- event.stopPropagation()
- event.preventDefault()
- event.stopImmediatePropagation()
- event.cancelBubble()
To prevent the event from reaching the parent menu when clicking a nested menu item, you can use the event.stopPropagation() method. This will stop the event from propagating up the DOM tree and prevent the parent menu's click event from being triggered. event.preventDefault() is used to prevent the default behavior of an event, not to stop event propagation.
Loading...
Related Quiz
- The ________ operator can be used to compare both value and type in JavaScript.
- Why might for...of loops be preferred when working with asynchronous code?
- What is "Promise chaining" in JavaScript?
- The ________ method is used to read a Response stream and return it as a blob.
- What is a practical use of closures in JavaScript?