When the correct string, foo, is entered into .guess I am trying to pull the value from .clicks and pass it into an alert. When I load the page with my current code (below) the alert reads Correct! You guessed it in clicks.. Why is the clicks variable not being passed?
Thanks
jQuery:
$('.guess').keyup(function() {
if ($('.guess').val() == "foo") {
var clicks = $('.clicks').val();
alert('Correct! You guessed it in ' + clicks + ' clicks.');
location.reload();
}
});
HTML:
<div class="bar">
<h2 class="clicks">0</h2>
<input type="text" class="guess" />
</div>