Vanilla JS - JavaScript Utilities

Utilities

$_("id")

Shorthand for document.getElementById()

$_("my-element-id");

$$_(".css .selector")

Returns an array of elements, corresponding to the given selector

$_(".my-parent .children");

Events

window.domReady(function)

Execute a function when the DOM is ready. (Thanks to Dustin Diaz)

Display

Element.hide(element)

Hide an element

Element.show(element)

Show an element

Element.toggleDisplay(element)

Toggle the display of an element

CSS Classes

Element.addClass(element, className)

Add a class to an element

I should be red

Element.hasClass(element, className)

Test if an element has a particular class

window.domReady(function(){ var testHasClass = Element.hasClass($_('addclass-test'), 'color-red'); });

Element.removeClass(element, className)

Remove a class from an element

I shouldn't be red

Element.toggleClass(element, className)

Toggle the class of an element

Result
Fork me on Github