Posted By

o0110o on 12/09/12


Tagged

javascript class element id


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

o0110o


Bare-Bones Selector Engine


 / Published in: JavaScript
 

This is a very basic wrapper for querySelectorAll. Just add prototypes and whatever else you need.

  1. var $ = function(selector, node) { // Bare-Bones Selector Engine
  2. var selector, node;
  3. selector = selector.trim();
  4. node = node || document.body;
  5. if (selector != null) {
  6. return Array.prototype.slice.call(node.querySelectorAll(selector), 0);
  7. }
  8. }
  9.  
  10. Array.prototype.put = function(html) {
  11. for (var i = 0; i < this.length; i++) {
  12. this[i].innerHTML = html;
  13. }
  14. return this;
  15. }
  16.  
  17. $('div').put('yay!');

Report this snippet  

You need to login to post a comment.