The Dom library currently provides functions for searching by and manipulating the HTML Element class attribute.
Determines if the browser supports the functions in Fork's DOM library. Returns true of so and false otherwise.
if (FORK.Dom.isSupported()) {
FORK.Dom.hasClass('foo', 'bar');
} else {
alert('Your browser does not support the Fork DOM library.');
}
Test an element to determine if it has a particular class name in it's class attribute. Returns true if the class name is detected or false otherwise.
alert(FORK.Dom.hasClass('myDiv', "apple"));
var div = document.getElementById('myDiv');
alert(FORK.Dom.hasClass(div, "apple"));
Adds a class name to the element class attribute if the class name is not already included.
FORK.Dom.addClass('myDiv', "orange");
var div = document.getElementById('myDiv');
var str = "pear";
FORK.Dom.addClass(div, str);
Removes a class name from the element class attribute if the class name is included.
FORK.Dom.removeClass('myDiv', "orange");
var div = document.getElementById('myDiv');
var str = "pear";
FORK.Dom.removeClass(div, str);
Find elements with a particular class name in the class attribute. Returns a JavaScript array of HTML elements. If no elements are found the returned array is empty.
root option is an HTML Element or string id of an element to be used as the parent node of the search down the DOM tree. The tag option is a string specifying the tag name that all returned elements must have.var finds = FORK.Dom.getElementsByClass('orange');
var finds = FORK.Dom.getElementsByClass('orange', {root:'myDiv'});
var finds = FORK.Dom.getElementsByClass('orange', {tag: 'li'});
var div = document.getElementById('div');
var str = 'li';
var finds = FORK.Dom.getElementsByClass('orange', {root:div, tag:str});
Class name functions modified from Yahoo! UI Dom collection.