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: 
What is your function doing? Is it some kind of aysnchronous event? If so then you would need to perform the default action in the success callback of the asynchronous task.

An example of this would be the jQuery `.load` function.

If your `mufunc` function were to call the jQuery `load` function it would return straight away, it will not wait for the data it self to be loaded. What you must do is use the second parameter in the `load` function as a callback for when the data has finished loading. This is the place you would then have your default action for the link.

This may be the issue you are experiencing with some other asynchronous task.

After you edited your code you have this line

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

```

This looks like the logout function is indeed some kind of asynchronous call and has a callback function. I may be wrong and it may be doing something else you would need to check the docs, but to me you should be doing anything you need to do in that callback function (for example the redirect).
To prevent opening of the link try:

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

```