Skip to content

Instantly share code, notes, and snippets.

@brunoannunciato
Forked from VitorLuizC/future-select.js
Created March 1, 2018 18:59
Show Gist options
  • Save brunoannunciato/8cb9aedcda0d6f483ea0a8b3d86b38a2 to your computer and use it in GitHub Desktop.
Save brunoannunciato/8cb9aedcda0d6f483ea0a8b3d86b38a2 to your computer and use it in GitHub Desktop.
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()
})
}
@brunoannunciato
Copy link
Author

FutureSelect('#form-que-surge').then(
(elements) => {
const form = elements[0]
form.submit()
}
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment