I'm trying to see how to load jQuery at run time. I can't understand why the following code doesn't work (probably me making a silly error)
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<script>
var script = document.createElement('script');
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js';
document.getElementsByTagName('head')[0].appendChild(script);
</script>
</head>
<body>
<a href="#" id="main">click me</a>
<script>
$('#main').click(function(){ alert('hi'); });
</script>
</body>
</html>
When I run this, '$' is not defined. What am I doing wrong?