Skip to content

Instantly share code, notes, and snippets.

@jatieu
jatieu / wait-element.js
Created December 27, 2021 10:12
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==========`)
@jatieu
jatieu / wait-element.js
Created December 27, 2021 10:17
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 = () => { $(e).length ? c() : --i && setTimeout(() => { loop() }, t) }
loop()
},
//Process
myFunc = () => { //Do something }
//Usage
check("element", 30, 500, myFunc)