Skip to main content
add new method
Source Link
Belter
  • 3.9k
  • 5
  • 50
  • 60

The first one, ideally with a real link to follow in case the user has JavaScript disabled. Just make sure to return false to prevent the click event from firing if the JavaScript executes.

<a href="#" onclick="myJsFunc(); return false;">Link</a> 

If you use Angular2, this way works:

<a [routerLink]="" (click)="passTheSalt()">Click me</a>.

See here https://stackoverflow.com/a/45465728/2803344

The first one, ideally with a real link to follow in case the user has JavaScript disabled. Just make sure to return false to prevent the click event from firing if the JavaScript executes.

<a href="#" onclick="myJsFunc(); return false;">Link</a> 

The first one, ideally with a real link to follow in case the user has JavaScript disabled. Just make sure to return false to prevent the click event from firing if the JavaScript executes.

<a href="#" onclick="myJsFunc(); return false;">Link</a> 

If you use Angular2, this way works:

<a [routerLink]="" (click)="passTheSalt()">Click me</a>.

See here https://stackoverflow.com/a/45465728/2803344

Post Made Community Wiki by Berker Yüceer
added 14 characters in body
Source Link
Zach
  • 24.8k
  • 9
  • 46
  • 50

The first one, ideally with a real link to follow in case the user has JSJavaScript disabled. Just make sure to return false to prevent the click event to take placefrom firing if the JSJavaScript executes.

<a href="#" onclick="myJsFunc(); return false;">Link</a> 

The first one, ideally with a real link to follow in case the user has JS disabled. Just make sure to return false to prevent the click event to take place if the JS executes.

<a href="#" onclick="myJsFunc(); return false;">Link</a> 

The first one, ideally with a real link to follow in case the user has JavaScript disabled. Just make sure to return false to prevent the click event from firing if the JavaScript executes.

<a href="#" onclick="myJsFunc(); return false;">Link</a> 
Source Link
Zach
  • 24.8k
  • 9
  • 46
  • 50

The first one, ideally with a real link to follow in case the user has JS disabled. Just make sure to return false to prevent the click event to take place if the JS executes.

<a href="#" onclick="myJsFunc(); return false;">Link</a>