Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Last active June 5, 2020 17:51
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 daliborgogic/de6d20c9545e9a33c09ec8814b92eb29 to your computer and use it in GitHub Desktop.
Save daliborgogic/de6d20c9545e9a33c09ec8814b92eb29 to your computer and use it in GitHub Desktop.
document.querySelectorAll('input[type=search]').forEach(input => {
input.addEventListener('mouseup', e => {
if (input.value.length > 0) {
setTimeout(() => {
if (input.value.length === 0) {
// do reset action here
}
}, 5)
}
})
}
// addEventListener version
const input = document.querySelector('input[type="search"]')
input.addEventListener('search', () =>
console.log('The term searched for was ' + input.value)
)
// onsearch version
const input = document.querySelector('input[type="search"]')
input.onsearch = () =>
console.log('The term searched for was ' + input.value)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment