I am new to ajax and it is the first time I am using the jQuery's load()
method.
The example bellow doesn't work. The variable inside doSomething()
is not defined (because of the asynchronously call I guess)
var x = jQuery("#div1 a"); // x is used in different parts of the code, not only for the doSomething function
jQuery('.test').load(homeUrl, function() {
doSomething();
};
function doSomething () {
x.css('background-color', 'yellow');
}
So, I am doing like this (which is repetitive) and it works:
function doSomething () {
var x = jQuery("#div1 a");
x.css('background-color', 'yellow');
}
But I would like to know if there is a better way of dealing with the variable or even if I am doing something wrong.