Which property of the event object is commonly used to prevent the default action of the event?
- event.stopPropagation()
- event.preventDefault()
- event.cancelBubble()
- event.halt()
To prevent the default action of an event in JavaScript, you commonly use the event.preventDefault() method. It stops the default behavior associated with the event, such as preventing a form from submitting or a link from navigating to a new page. This method is crucial for controlling the behavior of events.
Loading...
Related Quiz
- Which keyword is used to declare a variable with block scope?
- Which of the following methods can select multiple elements?
- How can a "for" loop be used to iterate through the properties of an object?
- A _______ function is a function that accepts up to three arguments: the value of the element, the index of the element, and the array object being traversed.
- How does the for...of loop handle objects by default?