Created
December 15, 2020 07:22
-
-
Save alaztetik/996f099073f7199ea8e98f62f6f97795 to your computer and use it in GitHub Desktop.
Get DOM elements quickly
This file contains 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
var el = function (element) { | |
if (element.charAt(0) === "#") { | |
// If passed an ID... | |
return document.querySelector(element); // ... returns single element | |
} | |
return document.querySelectorAll(element); // Otherwise, returns a nodelist | |
}; | |
// reference: https://codepen.io/giana/pen/GJMBEv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment