Problem to retrieve table rows with multiple classes

The following works if the row that i want to display has one class. But if it has two classes this don’t work.

for example this works

<tr class="testcase-failed-message">
<th>
testcase-failed-message
</th>
<th>
testcase-failed-message
</th>
</tr>

And this don’t since it has two classes. How can i have two classes on a tag and still chose wich one i want to use when i want to show them or not??

<tr class="testcase-failed-message failed-skipped">
<th>
testcase-failed-message
</th>
<th>
testcase-failed-message
</th>
</tr>

function show(){
doShow('testcase-failed-message');
}




function doShow(textstring) {

var allPageTags=document.getElementsByTagName("*");

for (i=0; i<allPageTags.length; i++) {

if (allPageTags[i].className==textstring || allPageTags[i].className==textstring2) {

allPageTags[i].style.display='none';
}


}
}

As well as felgall’s suggestion you can also use the indexOf method to check if the className contains the string…e.g:

if (allPageTags[i].className.indexOf(textString) != -1) {
alert(“contains this string”);
}

indexOf will return -1 if the string isn’t found.

You need to use a regular expression that tests if the string contains the class name with a boundary on either side rather than just testing if it is equal.

For example:

var myclass1 = new RegExp(‘\\b’+textstring+‘\\b’);
var myclass2 = new RegExp(‘\\b’+textstring2+‘\\b’);

and then

if (myclass1.test(allPageTags[i].className) || myclass2.test(allPageTags[i].className))