• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 16962
  • Last Modified:

document.getElementById style Q

I have this javascript:

if (window.XMLHttpRequest) {
      newLogoAsk = new XMLHttpRequest();
}
function getNewLogo() {
      if (window.XMLHttpRequest) {
      // branch for IE/Windows ActiveX version
      } else if (window.ActiveXObject) {
            newLogoAsk = new ActiveXObject("Microsoft.XMLHTTP");
      }
      newLogoAsk.onreadystatechange = newLogoChange;
      newLogoAsk.open("GET", "/scripts/randomheader.php");
      newLogoAsk.send(null);
}
function newLogoChange() {
      if (newLogoAsk.readyState == 4) {
            var imG = newLogoAsk.responseText;
            document.getElementById("logo").style.background = 'url(../img/headers/'+imG+') no-repeat left top';
      }else{
            document.getElementById("logo").style.background = 'url(../img/header_loading.jpg) no-repeat left top';
      }
}

which applies a new background style to "logo" in this code:

<div id="logo">
      <div id="shadow">
            <div id="nextimg">
                  <a href="javascript://" title="New Header!" onclick="getNewLogo()"><img id="photonext" src="img/header_button.gif" alt="New Header!"/></a>
            </div>
      </div>
</div>

so, everything here works wonderfully, IN FF. NOT in IE. I get the response back from the server, and everything is great, only:

document.getElementById("logo").style.background

doesn't seem to be working in IE!! Is there a solution???
0
D4Ly
Asked:
D4Ly
  • 3
  • 2
1 Solution
 
BatalfCommented:
You can try a few things

1)

instead of

document.getElementById("logo").style.background = 'url(../img/headers/'+imG+') no-repeat left top';

try

document.getElementById("logo").style.background = 'url(\'../img/headers/'+imG+'\') no-repeat left top';

i.e. with quotes.

An other alternative is to drop no-repeat and top left, and set that in the CSS instead

in the css

#logo{
    background-position: top left;
    background-repeat:no-repeat;
}

and then use backgroundImage in your function, i.e.

document.getElementById("logo").style.backgroundImage = 'url(\'../img/headers/'+imG+'\')';

Batalf


0
 
D4LyAuthor Commented:
THANKS!!!

If you're looking for a few more points, I'm having trouble with the javascript m8trix wrote here:
http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21418238.html

He stopped responding, and I am still in need of a solution!!
0
 
BatalfCommented:
I have sent you an alternative solution in the other question -  Did the comment above help you solve this question?

Batalf
0
 
D4LyAuthor Commented:
yes it did! I'm using the first approach with the \' for quotes.
0
 
BatalfCommented:
That's good - Glad I could help

Batalf
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now