First off, here’s my code:
var variable1 = 10;
function f1 (){
alert(variable1);
}
//When button is pressed, call function
$("#button").click(f1);
Why can I not access variable1 inside the function?
$(document).ready(function() {
var how_many_words = 3;
alert(how_many_words); //This happens
$("input").keypress(check_word);
function check_word() {
alert('hello'); //This happens
alert(how_many_words); //This doesn't
}
});
Here’s the definitive answer to what my problem was, courtesy of this website. I foolishly named one of my variables the same as an id and a function. Insanity! I apologise for wasting people’s boxing days. Thanks for all your help.