इसके लिए, JavaScript में preventDefault() का उपयोग करें। JavaScript कोड निम्न है -
उदाहरण
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> </head> <body> <a href="urlLink">Press Me to see logs</a> <a href="urlLink">Press Me to see logs in console</a> <a href="#">Nothing will happen</a> <script> $(function(){ $("a:not([href='#'])").click(function(event){ event.preventDefault(); console.log("You have pressed me!!!!!"); }); }); </script> </body> </html>उपरोक्त प्रोग्राम चलाने के लिए, फाइल का नाम anyName.html(index.html) से सेव करें और फाइल पर राइट क्लिक करें। VS कोड एडिटर में Open with live server विकल्प चुनें।
आउटपुट

यदि आप दो लिंक्स, Press Me to see logs और Press Me to see logs in console पर क्लिक करते हैं, तो आपको कंसोल आउटपुट मिलेगा। हालांकि, यदि आप लिंक Nothing will happen पर क्लिक करेंगे, तो यह कुछ भी प्रिंट नहीं करेगा -

ऊपर, मैंने आउटपुट प्रदर्शित करने के लिए Press Me to see logs दबाया।
यदि आप लिंक Nothing will happen पर क्लिक करते हैं, तो यह नीचे दिए गए आउटपुट की तरह कुछ भी प्रिंट नहीं करेगा -
