1

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.

asked Feb 7, 2010 at 0:21

2 Answers 2

7

$.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
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.