Created
August 12, 2014 01:33
-
-
Save mayfer/b4064f312f4b00c2f57f to your computer and use it in GitHub Desktop.
jQuery example demonstrating working with anonymous and named callbacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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