dojo.hasClass¶
Status: | Final |
---|---|
Version: | 1.0 |
Project owner: | Eugene Lazutkin |
Available: | since 0.9 |
Contents
Returns a boolean depending on whether or not a node has a passed class string.
Usage¶
The function takes two arguments:
- A DOM node or its node id (as a string).
- A CSS class name as a string.
It returns true if the node has the class, and false otherwise.
Consider the following html:
1 2 | <div id="bam" class="foo bar baz"></div>
<div class="something else"></div>
|
Using dojo.hasClass to find if the node id="bam" has class="foo":
1 2 3 | if(dojo.hasClass("bam", "foo")){
/* it does */
}
|
Using dojo.query to find a node and check if it has a class:
1 2 3 4 5 | dojo.query(".something").forEach(function(node){
if(dojo.hasClass(node, "else"){
/* it does */
}
});
|
Note: You do not need to explicitly check for dojo.hasClass before adding or removing a class with dojo.addClass or dojo.removeClass, they do it for you.