Example 6: Fieldset/Legend for grouping checkboxes
Best Practice Rating: Good
fieldset/legend elements are used to bind the group label information to the checkboxes in the group.
Screen readers read the legend element content when the one of the checkboxes in the group receives keyboard focus.
One problem with the legend element is the limited browser supporting in restyling the legend element with CSS.
Browsers only render legend as a single line, making long legends run off the visible screen or over other page content.
<script type="text/javascript">
//
// Add focus styling to the parent (LI) element of the radio button receiving focus
//
function parentFocus( event ) {
// Get event object if using Internet Explorer
var e = event || window.event;
// Check the object for W3C DOM event object, if not use IE event object to update the class of the parent element
if( e.target )
e.target.parentNode.className = "focus";
else
e.srcElement.parentNode.className = "focus";
}
//
// Remove focus styling from the parent (LI) element of the radio button receiving focus
//
function parentBlur( event ) {
// Get event object if using Internet Explorer
var e = event || window.event;
var node;
// Check the object for W3C DOM event object, if not use IE event object to update the class of the parent element
if( e.target )
e.target.parentNode.className = "";
else
e.srcElement.parentNode.className = "";