Created
December 27, 2021 10:12
-
-
Save jatieu/c57bb242bb4b0150b77f8027f051d26f to your computer and use it in GitHub Desktop.
Wait for an element to load with jQuery (Chờ cho 1 phần tử đã load với jQuery)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Check | |
let check = (e, m, t, c) => { //(element, max, timeout, callback) | |
let i = +m, | |
loop = () => { | |
if ($(e).length) { | |
console.log(`Atieu: Found ${e}\n==========`) | |
c() | |
} else { | |
if (--i) { | |
console.log(`Atieu: Find ${e} for the ${m - i} times\n==========`) | |
setTimeout(() => { loop() }, t) | |
} else { | |
console.log(`Atieu: Timeout!\n==========`) | |
} | |
} | |
} | |
loop() | |
}, | |
//Process | |
myFunc = () => { | |
//Do something | |
} | |
//Usage | |
check("element", 30, 500, myFunc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment