Skip to content

Instantly share code, notes, and snippets.

@juanbrujo
Created December 8, 2015 14:19
Show Gist options
  • Select an option

  • Save juanbrujo/464f9d83af01645d32dd to your computer and use it in GitHub Desktop.

Select an option

Save juanbrujo/464f9d83af01645d32dd to your computer and use it in GitHub Desktop.

Revisions

  1. juanbrujo created this gist Dec 8, 2015.
    7 changes: 7 additions & 0 deletions getElement.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    // Shortcut to get elements
    var $ = 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
    };