Let\'s say I want to build a non-dependent javascript framework/script. Is there a way to utilize jQuery\'s amazing class and element selecting functionality
The answer to "I need a small JS library that..." is this site: http://microjs.com/
specifically, you're looking for a selector engine:
http://microjs.com/#css
In everything but IE6 and IE7, you can use document.querySelectorAll
or someElement.querySelectorAll
to perform similar selection functionality.
Update more details:
It looks like ZeptoJS does the following. This uses quick functions for $$(document, '#myid')
, $$(document, '.myclass')
, $$(document, 'div')
and slow searches for $$(document, 'div > .myclass')
var classSelectorRE = /^\.([\w-]+)$/,
idSelectorRE = /^#([\w-]+)$/,
tagSelectorRE = /^[\w-]+$/;
$$ = function(element, selector){
var found;
return (element === document && idSelectorRE.test(selector)) ?
( (found = element.getElementById(RegExp.$1)) ? [found] : [] ) :
Array.prototype.slice.call(
classSelectorRE.test(selector) ? element.getElementsByClassName(RegExp.$1) :
tagSelectorRE.test(selector) ? element.getElementsByTagName(selector) :
element.querySelectorAll(selector)
);
}
Just try jBone, library for Events and DOM manipulation. jBone has much better performance then jQuery/Zepto, smaller size and full support for all selectors, events API's.
MicroSelector. Even smaller and faster than Zepto, which is smaller than Sizzle, which is smaller than JQuery.
You could do what jQuery does and use Sizzle: http://sizzlejs.com/
Have you looked at zepto.js? You'd still be dependent on a framework, but it's much lighter weight: about 5kb instead of 31kb.