Skip to content

Instantly share code, notes, and snippets.

@alaztetik
Created December 15, 2020 07:22
Show Gist options
  • Save alaztetik/996f099073f7199ea8e98f62f6f97795 to your computer and use it in GitHub Desktop.
Save alaztetik/996f099073f7199ea8e98f62f6f97795 to your computer and use it in GitHub Desktop.
Get DOM elements quickly
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