The first time I try to use my jQuery lessons on a real web page, I find that the variable guess
(inside the scope of this inner function) disappears as soon as the function completes.
This is normal javascript behavior, I suppose, but how does one usually grab hold of the variable so one can use it in other functions? My lessons never covered that.
I assumed that once guess
was routed into the innerHTML of #display
, it would stick. But it's even disappearing from there.
?
<!DOCTYPE html>
<html>
<HEAD>
<title>Game of the Century</title>
<meta charset="UTF-8">
<LINK href="reset.css" rel="stylesheet" type="text/css">
<LINK href="main.css" rel="stylesheet" type="text/css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="application.js"></script>
</HEAD>
<body>
<form>
<input type='text' name = "input" id = "input"><br>
<input type='submit' id="submit">
</form>
<p id = "display"></p>
<div>
<img src="http://img707.imageshack.us/img707/2403/rj1a.jpg" alt = "ad">
</div>
</body>
</html>
...
$(document).ready(function () {
$('#submit').click( function() {
var guess = $('#input').val();
$("#display").html(guess);
});
});