Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Prevent Default</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <a href="https://codingwithsonu.com" class="block">Click link</a> <script> $("a.block").on("click", function(e){ e.preventDefault(); alert("Default prevented!"); }); </script> </body> </html>
Output