I have a javascript function that is called when a link is clicked. However I just want the function to run without the link redirecting. I have heard I should use return false but it doesn’t work!
function hideaddclasses(e){
var element = document.getElementById("addclasses");
if(element.style.display=="none"){
element.style.display="";
}else{
element.style.display="none";
}
e.preventDefault();
return false;
}
Then for the html I simply have:
<a href='#' onclick='hideaddclasses()'>[ Hide ]</a>
Why does it still redirect?
(Note the
return).