Skip to content

Instantly share code, notes, and snippets.

@mevius6
Last active July 13, 2021 04:22
Show Gist options
  • Select an option

  • Save mevius6/fce49167a9962f1afe168404847ca9ca to your computer and use it in GitHub Desktop.

Select an option

Save mevius6/fce49167a9962f1afe168404847ca9ca to your computer and use it in GitHub Desktop.
const doc = document;
const select = (expr, con) => (con || doc).querySelector(expr);
const selectAll = (expr, con) => {
return Array.prototype.slice.call((con || doc).querySelectorAll(expr));
}
const selectFromData = (expr, con) => selectAll(`[data-${con}]`)
.find(item => item.dataset[con] === expr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment