Question: I have html-link, and I want to add event listener to `<a>` tag, so javascript function is called and after that brouser opens a link. I tried to use `document.getElementById('link').addEventListener("click", myfunc);`, but it works chaotically, sometimes myfunc is called, and after that link is opened, sometimes link is opened, so myfunc isn't called. How to set order of these events?

Code paths : 

HTML :

```
<a href="<%= Url.Action("LogOut", "Account") %>" id="logoutlink">LogOut</a>

```

Javascript :

```
function LogOutWithoutReload(e) {
VK.Auth.logout(function () { });}

```

`document.getElementById('logoutlink').addEventListener("click", LogOutWithoutReload);`

Answer: 
The event handler will *always* be called before the browser navigates away. My guess is that your function does not work sometimes, causing a exception and not stopping the default action. Have you tried debugging it? There should be some messages in your (error) console.
To prevent opening of the link try:

```
 document.getElementById("link").onclick = function(event) {
    event.preventDefault();
    myFunc();
 }

```