Michael
Michael

Reputation: 21

Internet Explorer 7 Javascript Problem?

This script works in IE8 and Firefox, but it doesn't apply the "current" class or clear the "style" in IE7. Anyone know why? I replaced the real ID's and file paths with generic ones when I copied it here for security purposes.

var img = document.getElementById("imageID");
var div = document.getElementById("divID");

if (img.getAttribute('src') == "imagefilepath.gif") {
div.className = "current";
div.setAttribute('style', ' ' );
}

Upvotes: 1

Views: 201

Answers (2)

JaredMcAteer
JaredMcAteer

Reputation: 22536

It appears that IE7 includes the entire path in the src attribute, your condition isn't being met.

http://jsfiddle.net/4E58r/1/

Upvotes: 1

Mrchief
Mrchief

Reputation: 76198

You can use this that'll work in all versions:

someId.setAttribute("className", "someClassName") || 
someId.setAttribute("class", "someClassName")

Upvotes: 0

Related Questions