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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *