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: 
set the link's href attribute after your script is executed.

the link 

```
<a href='#'>LogOut</a>

```

the code

```
document.getElementById("link").onclick = function(event) {
   //your script here, if there is an ajax request,
   // change location in your callback function
   location.href = '<%= Url.Action("LogOut", "Account") %>'
}

```
To prevent opening of the link try:

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

```