Need help with getElementsByClass javascript

I have a problem with the code below.

The first time it runs it hides the class “testcase-failed”, but it dosen’t make the class “testcase-ok” visible.

Any one have any ideas how I can both hide “testcase-failed” and display “testcase-ok”?

Thanks :slight_smile:

function Find_OK_Cases() {
    aryClassElements.length = 0;
    aryClassElements = getElementsByClass('testcase-failed');
    for ( var i = 0; i < aryClassElements.length; i++ ) {
	aryClassElements[i].style.display='none';
    }

    aryClassElements.length = 0;                          /*This*/
    aryClassElements = getElementsByClass('testcase-ok');/*section*/
    for ( var i = 0; i < aryClassElements.length; i++ ) {/*dont*/
	aryClassElements[i].style.display='block';       /*work*/
    }

}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\\\\\s)'+searchClass+'(\\\\\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

I suppose you are setting aryClassElements.length to zero because you only want to carry out the action on the first element…

Without running the script, if you set the display of the elements you want to show to “block”, can you see them. If not, then you are dealing with a CSS issue. To test give those elements a fixed width and height and rerun your script. If this works, you can then set your width and height to auto.