$class
Select element by class name
$class( element, className, callback )
element [object]
The parent element containing elements with the class name looking for.className [string]
The class name name of elements.callback (optional) [function]
The callback function for each matched elements.
Notes
The replacement of getElementsByClassName(). To increase the performance, Qatrix requires the parent element before searching elements with class name.
Example
HTML code
<div id="box_wrap"> <div class="box">This is box 1</div> <div class="box">This is box 2</div> <div class="box">This is box 3</div> </div> <div class="box">This is the box outside the box_wrap.</div> <button onclick="select_boxes()">select boxes</button>
CSS code
.box {
width: 100px;
height: 80px;
margin: 10px 0;
font-size: 12px;
background: #5599bb;
padding: 10px;
}JavaScript code
function select_boxes()
{
$class( $("box_wrap"), "box", function (item)
{
$css.set( item, 'background-color', '#cccccc' );
});
}
Demonstration
This is box 1
This is box 2
This is box 3
This is the box outside the box_wrap.