Toggle.js

Allows you to toggle one or more HTML elements.

View the Project on GitHub manngo/toggle.js

toggle.js

Make selected element(s) togglable, if that’s a real word.

Allows you to toggle one or more HTML elements. This can be useful, for example to generate menus, tabs or accordions.

This will be incorporated in a more extensive Widgets collection (TBA), but, because of its usefulness, this simpler version will still be maintained.

Click Here for a sample.

Usage

In JavaScript, invoke the following:

toggle(selector,attribute,options);

In CSS, you can select a toggled element as follows{

element[attribute] {
    
}

Parameters

element
HTML Element, such as from document.getLementById().
Can be a CSS style selector such as 'ul#menu>li'
attribute
blah blah
options
An array of options. This is in the form of:
{
    only: false,
    bubbleOK: false,
    callback: undefined,    
}

Options

The options object is, well, optional. If omitted, the values are as above.

If you want to set any options supply an object with any of the above properties.

only
Whether selecting an element will de-select others.
bubbleOK
Whether nested inner elements can activate the toggle.
callback
A function which will be called on toggling.