*Most major features from half$
have been merged over into cash
.
A micro alternative to jQuery using modern browser methods.
Working with vanilla Javascript can be painful and time consuming, but using 50kb+ worth of jQuery is overkill for a few DOM manipulations. Creating a custom build of jQuery with only the desired modules can still produce a 30+kb file.
HalfDollar.js gives you most of the familiar jQuery API in modern browsers, but at a fraction of the size (7.9kb minified, 2.8kb gzipped!). The goal is not full feature-parity, but simple & lightweight DOM access.
Browser Support: IE9+ and last 2 browser versions
Inspired by the brilliant youmightnotneedjquery.com
Simply include the minified HalfDollar.js and use it like you would the basic features of jQuery.
<script src="js/HalfDollar.min.js"></script>
If you need support for older browsers like IE8, fallback to jQuery v1! Use Google's Hosted Libraries or change the url to use your own local copy.
<script src="js/HalfDollar.min.js"></script>
<script>
(function(half$,s,u){ if ( !half$ ) {
var sc = document.createElement(s); sc.src = u;
var f = document.getElementsByTagName(s)[0]; f.parentNode.insertBefore(sc, f);
} }(window.half$,'script','https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js'));
</script>
Be sure to wrap your code in a DOM ready call $(function(){ ... });
and HalfDollar.js will queue up your code until the fallback loads. Plugins declared via $.fn.extend
should also be added to jQuery after it loads.
Please submit issues and patches where fitting. Optimizations are welcome.
HalfDollar.js tries to provide API compatibility where possible. Edge cases and more complex features may be missing or incomplete.
- each
- get
- eq
- first
- last
- clone
- is
- find
- filter
- children
- parent
- css
- addClass
- removeClass
- toggleClass
- hasClass
- attr
- removeAttr
- data
- removeData
- prop
- removeProp
- val
- height
- outerHeight
- width
- outerWidth
- position
- offset
- offsetParent
- html
- text
- empty
- remove
- append
- prepend
- appendTo
- prependTo
- hide
- show
- on
- off
- one
- $.ajax
- $.get
- $.post
- .trigger
- .makeArray, .toArray
- .map, .slice
- fully test AJAX implementation
- Separate modules and allow for custom builds
- .insertBefore, .insertAfter ?
- .parents ?
- .next, .prev ?
- .siblings ?
- .scrollLeft, .scrollTop ?