Skip to content

Instantly share code, notes, and snippets.

@jatieu
Created December 27, 2021 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jatieu/c57bb242bb4b0150b77f8027f051d26f to your computer and use it in GitHub Desktop.
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)
//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