Prevent a link from opening the URL, and check if preventDefault() was called:
document.getElementById("myAnchor").addEventListener("click", function(event){
event.preventDefault()
alert("Was preventDefault() called: " + event.defaultPrevented);
});
Try it Yourself »
The defaultPrevented event property checks whether the preventDefault() method was called for the event.
event.defaultPrevented
Return Value: | A Boolean, indicating whether the preventDefault() method was called for the event. Possible values:
|
---|---|
DOM Version: | DOM Level 3 Events |
event.delfaultPrevented()
is a DOM Level 3 (2004) feature.
It is fully supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!