micro selector library

by James Doyle

HTML

<div id="iddiv" class="classdiv" name="namediv">
    <div class="inside"></div>
</div>

JavaScript

(function(window, undefined) {
  var regex = /[=#@.?]/,
  fns = [];
  fns['#'] = function (q) {
    return document.getElementById(q);
  }
  fns['.'] = function (q) {
    return document.getElementsByClassName(q);
  }
  fns['@'] = function (q) {
    return document.getElementsByName(q);
  }
  fns['='] = function (q) {
    return document.getElementsByTagName(q);
  }
  fns['?'] = function (q) {
    return document.querySelectorAll(q);
  }
  function Salt(selector) {
    var type = regex.exec(selector)[0],
    ssel = selector.split(type)[1],
    el = fns[type](ssel);
    el = (typeof (el.length) == 'undefined') ? el : el[0];
    return el;
  }
  window.Salt = window.$ = Salt;
})(window);