How to execute a javascript using href? [closed]

1

I would like to run javascript down using href . But by clicking on the supposed Log Out link, nothing happens. If I keep the cursor on the link it shows me the destination as javascript:logout()

function logout() {
    var choose = confirm("Deseja realmente sair?");
    if (choose == true) {
        location="Main.html";
    } else {
			
    }
<nav id="menuOp"> 
    <a href="javascript:logout()">Log Out</a></br>
    <b>Olá, #</b>
</nav>
    
asked by anonymous 28.08.2015 / 22:11

1 answer

6

Your script failed to close the logout function

logout(){ 
   //conteudo
}

You can also change the href by onclick:

<a onclick="javascript:logout()">Log Out</a>
    
28.08.2015 / 22:16