Bare-Bones Selector Engine


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.