Q:

Cancel the default action (navigation) of the click using jquery

0

Cancel the default action (navigation) of the click using jquery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Cancel the default action (navigation) of the click.</title>
</head>
<body>
<a href="https://www.w3resource.com/">Clicked anchors will not take the browser to a new URL</a>
<p id="log"></p>
</body>
</html>

JavaScript Code :

$( "a" ).click(function( event ) {
event.preventDefault();
$( "<p>" )
.append( "Default " + event.type + " prevented" )
.appendTo( "#log" );
});

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now