1

I'm receiving Uncaught TypeError: success is not a function at the following code snippet:

waitFor(document.getElementsByClassName('class'), validate);

function waitFor(element, success) {
    if (element == null || element.length == 0) {
        setTimeout(function() { waitFor(element); }, 100);
    } else {
        success(element);
    }
}

function validate(element) {
    //do stuff
}

And my question is why am I receiving this error? validate function is properly defined below. I'm passing it as parameter of waitFor function and than success is undefined inside waitFor. I was passing function as parameter in javascript per this answer: https://stackoverflow.com/a/13286241/5449709

What am I missing?

Daniel Stradowski
  • 3,466
  • 1
  • 12
  • 21

1 Answers1

1

when you are calling

setTimeout(function() { waitFor(element); }, 100);

success is undefined and hence can throw an error

marvel308
  • 10,288
  • 1
  • 21
  • 32