I have this jQuery script:
$(content).find('data').each(function(){
// parsing some data
$(this).find('something').each(function(){
$(this).find('something new').each(function(){
// etc.
}};
});
});
...and I want to call function XYZ() after this script has finished.
This isn't working (it will call function XYZ() too early):
$(content).find('data').each(function(){
// parsing some data
}, XYZ());
Are there any solutions? Thank you.
2 Answers 2
$.each isn't asynchronous, so you don't need a callback per se. This will work:
$(content).find('data').each(function(){
// parsing some data
$(this).find('something').each(function(){
$(this).find('something new').each(function(){
// etc.
});
}};
});
XYZ();
answered Feb 7, 2010 at 0:24
Dave Ward
60.7k14 gold badges119 silver badges134 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
in case you have any asynchronous process, you should call "XYZ ()" in "/ / etc."
var xData $(content).find('data'),
lenData = $(xData).length;
if (lenData==0){
XYZ();
}
else{
$.each(xdata, function(index, value){
// parsing some data
var xsomething = $(this).find('something')
lenxsomething = $(xsomething).length;
if ((lenxsomething==0) && (lenData==(index+1))){
XYZ();
}
else{
$.each(xsometing, function(index2, value2){
var xsomethingNew $(this).find('something new')
lenxsomethingNew = $(xsomething).length;
if ((lenxsomethingNew==0) && (lenxsomething==(index2+1))){
XYZ();
}
else{
$.each(xsomethingNew, function(index3, value3){
//etc ..
//then asynchronous process
if (lenxsomethingNew==(index3+1)){
XYZ();
}
});
}
});
}
});
}
answered Feb 7, 2010 at 1:06
andres descalzo
15k14 gold badges66 silver badges119 bronze badges
Comments
lang-js