# Javascript div bg image check

**URL:** <https://forum.kirupa.com/t/javascript-div-bg-image-check/175181>\
**Category:** Uncategorized\
**Created:** [January 12, 2006, 10:00am UTC](https://forum.kirupa.com/t/javascript-div-bg-image-check/175181 "2006-01-12T10:00:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrunkenMajestic](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/drunkenmajestic/32/237_2.png) [@DrunkenMajestic](https://forum.kirupa.com/u/DrunkenMajestic)\
**Post date:** [January 12, 2006, 10:00am UTC](https://forum.kirupa.com/t/javascript-div-bg-image-check/175181/1 "2006-01-12T10:00:21Z")

</div>

I have a simple script that checks if a particular file is the background image for a given div befpre swapping the image for a rollover effect. The code I have works perfectly in firefox and IE, but i can’t get it to work in safari or IE:Mac. I was wondering if anyone knew of a work around for this problem.

The working firefox/IE code is as follows:

```auto

function hover(button) {
	if (document.getElementById(button).style.backgroundImage != "url(/images/buttons/"+button+"_down.gif)") {
		document.getElementById(button).style.backgroundImage="url(images/buttons/"+button+"_on.gif)";
	}
}

```

To clarify…what doesnt work is the check in the if statement…this seems to allow the contents of the if statment to be executed in safari or IE:MAC, regardless of whether the != check is true or not…

Thanks for your help in advance.
