i am currently using <a href="somelink.com"><a/>
and on click the href the href and Dom event both are called i need only DOM event to be called href should be only used for opening link in new tab
Asked
Active
Viewed 48 times
-3

Rory McCrossan
- 331,213
- 40
- 305
- 339
1 Answers
-1
Please try this solution. I hope it will help you.
<html>
<head>
<meta charset="utf-8" />
<title>Test</title>
</head>
<body>
<a href="https://stackoverflow.com" id="myLink"> My Link</a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script>
$("#myLink").click(function(e) {
event.preventDefault();
/** Do your code here */
console.log("Event Triggered");
});
</script>
</body>
</html>

Alok Mali
- 2,821
- 2
- 16
- 32
-
OP hasn't asked for jQuery solutions. On top of that, you missed the relevant *href should be only used for opening link in new tab* part. – connexo Jun 06 '19 at 14:12
```
– axel axel Jun 06 '19 at 13:52