Remove the var
in your variable declaration.
Clarification: You're defining that variable with var so it is only accessible within the scope of that function and any functions defined immediately within it. If you just use myVar = 15;
(without the var
), the variable will be defined within the global scope. In the browser, this is equivalent to using window.myVar = 15
.
Further clarification: Use of global variables usually means you're doing something you shouldn't be. I'm not a purist, but I get the feeling that many people will cry foul. You're running the risk that you reassign that global variable to another value before your callback function has been triggered - it can be a pain in the butt to debug such scoping issues.
In your example, why not just pass the variable to the function, like nu(itemTitle);
:
function nu(itemTitle){
/* blah blah blah */
/*
* itemTitle is now available here and directly
* in any functions that are defined in this
* part of the code
*/
}