-
-
Save brunoannunciato/8cb9aedcda0d6f483ea0a8b3d86b38a2 to your computer and use it in GitHub Desktop.
This file contains 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
const FutureSelect = (selector, parent = document) => { | |
let request = null | |
return new Promise((resolve) => { | |
const select = () => { | |
const elements = parent && [ ...parent.querySelectorAll(selector) ] || [] | |
if (!elements.length) { | |
request = requestAnimationFrame(select) | |
return | |
} | |
cancelAnimationFrame(request) | |
resolve(elements) | |
} | |
select() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FutureSelect('#form-que-surge').then(
(elements) => {
const form = elements[0]
form.submit()
}
)