Skip to content

Instantly share code, notes, and snippets.

@mayfer
Created August 12, 2014 01:33
Show Gist options
  • Save mayfer/b4064f312f4b00c2f57f to your computer and use it in GitHub Desktop.
Save mayfer/b4064f312f4b00c2f57f to your computer and use it in GitHub Desktop.
jQuery example demonstrating working with anonymous and named callbacks
<html>
<head>
<style>
body { background: #358; color: #fff; padding: 50px; font-family: sans-serif; }
</style>
<!-- we need to load jquery before we use it -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
function changeMyMind(amount) {
$('#response').html("wait, you only have $" + amount + "? hmm nvm");
};
$(document).ready(function() {
$('.clickable').on('click', function() {
var amount = $('input[type="text"]').val();
$('#response').html("i dont care you are still beautiful");
setTimeout(changeMyMind, 2000, [amount]);
});
});
</script>
</head>
<body>
How much money do you have? <br />
$<input type="text" name="money" />
<input type="submit" value="Am i rich?" class="clickable" />
<div id='response'></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment