SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Change of background image works in IE only

    Hi,

    I'm using javascript to change the background image of a table field. I've found that it only works correctly in IE. In FF etc, it simply doesn't change.

    What I have is:
    Head
    HTML Code:
    function Info(infolink, titlelink){
    document.getElementById('Info').src=infolink;
    document.getElementById('subTitle').background=titlelink;
    }
    Body
    HTML Code:
    <td width="343" id="subTitle" name="subTitle" height="33" valign="top" background="images/aboutustitle.png">
    
    
    <a href="javascript:Info('aboutus.html','images/aboutustitle.png')"></a>
    <a href="javascript:Info('whyus.html','images/whyustitle.png')"></a>
    The subTitle field background will only change in IE and I can't figure out why.

    Could anyone please help me out?

    Thanks,
    Rhys

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're going to be mixing your JavaScript in with your mark-up like that, then consider using the style attribute rather than the background attribute:
    Code:
    document.getElementById('subTitle').style.backgroundImage= "url('" + titlelink + "')";

  3. #3
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh of course. Too many late nights I guess :P

    Thanks r51.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •