# Javascript: DOM Issue or bad code?

**URL:** https://forum.kirupa.com/t/javascript-dom-issue-or-bad-code/206203
**Category:** web dev
**Created:** [November 6, 2006, 4:34am UTC](https://forum.kirupa.com/t/javascript-dom-issue-or-bad-code/206203 "2006-11-06T04:34:25Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![denizengt](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@denizengt](https://forum.kirupa.com/u/denizengt)
#### Post date: [November 6, 2006, 4:34am UTC](https://forum.kirupa.com/t/javascript-dom-issue-or-bad-code/206203/1 "2006-11-06T04:34:25Z")

</div>

```auto
function mouseOver() {
    
    if (!document.body.getElementsByTagName){ return; }
    var allfields = new Array();
    allDivs = document.body.getElementsByTagName("DIV");
    for (var i=0; i<allDivs.length; i++){
        var field = allDivs*;
        if (field.getAttribute('class') == "greyBox") {
            field.onmouseover = function () {this.className = 'greyBoxHover';}
            field.onmouseout = function () {this.className = 'greyBox';}
        }
    }
}

```

I wrote this function to change the background of DIV’s going by the class “greyBox”. When the page loads it is initialised - it works in Firefox, but doesn’t in IE. As far as I know, getElementsByTagName is supported in both browsers - and I’ve tested for null returns.

Does anyone know why it doesn’t work in IE (5.5, 6)?
