jquery exercises

jQuery: Cancel the default action of the click

jQuery Fundamental - II : Exercise-92

Cancel the default action (navigation) of the click.

Sample solution :

HTML Code :

<!DOCTYPE html>
<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>
<a href="https://www.w3resource.com/">Clicked anchors will not take the browser to a new URL</a>
<p id="log"></p>

JavaScript Code :

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

See the Pen jquery-fundamental-exercise-92 by w3resource (@w3resource) on CodePen.

Contribute your code and comments through Disqus.

Previous: Display the mouse position relative to the left and top edges of the document (within this iframe).
Next: Display previous handler's return value.

What is the difficulty level of this exercise?

New Content: Composer: Dependency manager for PHP, R Programming