indexOf(value)
returns -1
when no match, and a index starting with 0
when there is match.
In your case, you should compare the result with 0, instead of 1.
Note that, if you want to test if a node has some certain class name, this is not a good practice.
A better approach is to use DOM API node.classList.contains()
which is available in modern browsers.
Or use regular expression /\bblah\b/.test(node.className)
to avoid the cases that blah
is a substring of another class name, say not-blah
.
Another way is to use mootools, which provides node.hasClass()
to HTMLElement
instances.
Or use jQuery like $(node).hasClass()
.