Last active
May 7, 2020 15:06
-
-
Save luislobo14rap/b9cb92fdcd53798c75cfc6f49f08eaff to your computer and use it in GitHub Desktop.
getElement and getElements
This file contains hidden or 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
| // 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