Skip to content

Instantly share code, notes, and snippets.

@ungoldman
Created October 25, 2012 20:52
Show Gist options
  • Save ungoldman/3955315 to your computer and use it in GitHub Desktop.
Save ungoldman/3955315 to your computer and use it in GitHub Desktop.
jQuery click bind switch example
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<a href="#" class="button">hi</a>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var $button = $('.button');
function bindOne(event){
event.preventDefault();
$(this).unbind('click.woot').on('click.woot', bindTwo);
console.log('woot 1');
}
function bindTwo(event){
event.preventDefault();
$(this).unbind('click.woot').on('click.woot', bindOne);
console.log('woot 2');
}
$button.on('click.woot', bindOne);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment