Skip to content

Instantly share code, notes, and snippets.

@luislobo14rap
Last active May 7, 2020 15:06
Show Gist options
  • Select an option

  • Save luislobo14rap/b9cb92fdcd53798c75cfc6f49f08eaff to your computer and use it in GitHub Desktop.

Select an option

Save luislobo14rap/b9cb92fdcd53798c75cfc6f49f08eaff to your computer and use it in GitHub Desktop.
getElement and getElements
// query-elements.js v1
function getElement(query, scope) {
if (typeof scope === 'undefined') {
scope = window.document;
};
if (typeof query === 'string') {
return document.querySelector(query, scope);
} else {
throw new Error('The argument "query" must be String.');
};
};
function getElements(query, scope) {
if (typeof scope === 'undefined') {
scope = window.document;
};
if (typeof query === 'string') {
return document.querySelectorAll(query, scope);
} else {
throw new Error('The argument "query" must be String.');
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment