Last active
April 7, 2016 20:53
-
-
Save tmcw/5962009 to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="https://yandex.st/highlightjs/7.3/styles/default.min.css"> | |
<script src="https://yandex.st/highlightjs/7.3/highlight.min.js"></script> | |
<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script> | |
<style> | |
body, pre { | |
margin:0; padding:0; font:normal 12px/20px sans-serif; | |
} | |
.left { | |
background:#ccc; | |
text-align:center; | |
} | |
.left, .right { | |
width:50%; | |
float:left; | |
} | |
.pad { | |
padding:10px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class='left'> | |
<div class='pad'> | |
<button id='button'>add a number</button> | |
<button id='two'>add two numbers</button> | |
<h2 id='count'>0</h2> | |
</div> | |
</div> | |
<div class='right'> | |
<pre><code id='code' class='javascript'>var myNum = 0; | |
// a callback can be an anonymous function | |
$('#button').click(function() { | |
$('#count').text(++myNum); | |
}); | |
function youClicked() { | |
myNum += 2; | |
$('#count').text(myNum); | |
} | |
// or it can be a named function | |
$('#two').click(youClicked); | |
</code></pre> | |
</div> | |
<script type='text/javascript'> | |
eval($('#code').text()); | |
hljs.initHighlightingOnLoad(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment