How to perform an action when finishing each() Jquery

Asked

Viewed 222 times

1

I’m using the function each() of Jquery would like to know if there is a mechanism so that I can perform a function after the each().

As soon as I finish mine each(), I can do something else, but it didn’t work.

$(".budgetSelectedNumber").each(function () {
       let value = Number($(this).val());
       arrayProductSelecteds.push(value)
}).done(function(){
       console.log("finish")
});

Uncaught Typeerror: $(...). each(...). done is not a Function

1 answer

3


The implementation of the Code will only continue after the completion of the $.each(). That is, the next line after the $.each() shall be executed only when the $.each() finalize:

$(".budgetSelectedNumber").each(function () {
    let value = Number($(this).val());
    arrayProductSelecteds.push(value);
});

console.log("O each terminou!");

So you don’t need any specific function or a callback for that, because it doesn’t have (see the documentation).

  • I thought my problem was no each() but you’re right, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.