library and want to use the same technique in your jQuery code. In
this case, it’s the
method from the Ext Core library,
which adds a class to the matching element(s) and
removes the same class from all siblings of the
comes from the behavior of radio buttons in both web applications
and desktop apps, where clicking one button selects it and deselects
the other buttons in the same radio button group.
The name radio button for those input elements comes from the station buttons in old car radios—the mechanical ones where pushing in one button caused all of the other buttons to pop out.
Given this HTML:
<div> <div id="one" class="hilite">One</div> <div id="two">Two</div> <div id="three">Three</div> <div id="four">Four</div> </div>
you’d like to run code like this:
// Add the 'hilite' class to div#three, and // remove the class from all of its siblings // (e.g. div#one) $('#three').radioClass('hilite');
You may even want to allow a “multiple-select” radio class:
// Add the 'hilite' class to div#two and // div#four, and remove the class from the // other siblings (div#one and div#three) $('#two,#four').radioClass('hilite');
Write a simple plugin to add the .
radioClass() method to jQuery:
// Remove the specified class from every sibling of the selected // element(s), then add that class to the selected element(s). // Doing it in ...