Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 25, 2014 10:41
Show Gist options
  • Save bennadel/9758999 to your computer and use it in GitHub Desktop.
Save bennadel/9758999 to your computer and use it in GitHub Desktop.
Preventing Default Actions In A Bubbled Event In jQuery
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Event Bubbling In jQuery</title>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript">
// When the DOM is ready to be interacted with,
$(function(){
// Bind click event handling on the UL. This will allow
// us to handle both link and LI clicks in one place
// by leveraging event bubbling.
$( "ul" ).click(
function( objEvent ){
// Return FALSE to prevent the default.
return( false );
}
);
});
</script>
</head>
<body>
<h1>
Event Bubbling In jQuery
</h1>
<ul>
<li>
Go to <a href="http://www.t-nation.com">T-Nation</a>
</li>
<li>
Go to <a href="http://www.cfbloggers.com">CF Bloggers</a>
</li>
<li>
Go to <a href="http://www.nycfug.com">NY CFUG</a>
</li>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment