How come I cannot access this global variable in my console?
let url;
$("li").click(function(){
let url = $(this).text();
console.log(url);
});
The console prints out whenever I click, but if I type in console.log(url)
manually, the console returns undefined
. It seems to me that it can work locally but not globally. I want what's clicked in the list to be accessed through a global variable.
My goal is to store the text which I clicked in a list so it can be accessed somewhere in another page or app as a string in a global variable, not a local one.