How do I prevent redirection after clicking a hyperlink?
I have the following html + js code:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<a href="#" id=key onclick="func(0)">foo</a>
</body>
<script type="text/javascript">
function func(k){
alert(1);
return false;
}
</script>
</html>
Can you explain how to refactor the following code that, after clicking on the href code, func
executes, but # does not add the url and the page should not reload?
+5
source to share