Cannot Insert Preloaded Background Image into TR, TD in IE

Discussion in 'Javascript' started by vunet.us@gmail.com, May 8, 2007.

  1. Guest

    why am i unable to insert image background into a tr or td element in
    IE using preloaded image object, like this:

    var img = new Image();
    img.src = 'blah.gif';
    document.getElementById('someId').style.backgroundImage =
    "url('"+img.src+"')";

    <table><tr id='someId'><td>content</td></tr></table>
     
    , May 8, 2007
    #1
    1. Advertising

  2. Evertjan. Guest

    wrote on 08 mei 2007 in comp.lang.javascript:

    > why am i unable to insert image background into a tr or td element in
    > IE using preloaded image object, like this:
    >
    > var img = new Image();
    > img.src = 'blah.gif';
    > document.getElementById('someId').style.backgroundImage =
    > "url('"+img.src+"')";
    >
    > <table><tr id='someId'><td>content</td></tr></table>
    >
    >


    Works fine over here in IE7.
    The id-ed element must be ready, of course.

    <table><tr id='someId'>
    <td>content<br><br><br><br><br><br><br><br>
    </td></tr></table>

    <script type='text/javascript'>
    var img = new Image();
    img.src = 'blah.gif';
    document.getElementById('someId').style.backgroundImage =
    "url('"+img.src+"')";
    </script>

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., May 8, 2007
    #2
    1. Advertising

  3. ASM Guest

    a écrit :
    > why am i unable to insert image background into a tr or td element in
    > IE using preloaded image object, like this:
    >
    > var img = new Image();
    > img.src = 'blah.gif';


    is the document completly loaded when you do the following ?

    > document.getElementById('someId').style.backgroundImage =
    > "url('"+img.src+"')";


    onload = function() {
    var d = document.getElementById('someId').style
    d.backgroundImage = 'url('+img.src+')';
    }

    works with my FF, IE(mac), Safari and some others

    > <table><tr id='someId'><td>content</td></tr></table>




    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
     
    ASM, May 8, 2007
    #3
  4. Guest

    On May 8, 9:57 am, "Evertjan." <> wrote:
    > wrote on 08 mei 2007 in comp.lang.javascript:
    >
    > > why am i unable to insert image background into a tr or td element in
    > > IE using preloaded image object, like this:

    >
    > > var img = new Image();
    > > img.src = 'blah.gif';
    > > document.getElementById('someId').style.backgroundImage =
    > > "url('"+img.src+"')";

    >
    > > <table><tr id='someId'><td>content</td></tr></table>

    >
    > Works fine over here in IE7.
    > The id-ed element must be ready, of course.
    >
    > <table><tr id='someId'>
    > <td>content<br><br><br><br><br><br><br><br>
    > </td></tr></table>
    >
    > <script type='text/javascript'>
    > var img = new Image();
    > img.src = 'blah.gif';
    > document.getElementById('someId').style.backgroundImage =
    > "url('"+img.src+"')";
    > </script>
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)


    thank you for inspiration! i just did something wrong...
     
    , May 8, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Homa
    Replies:
    2
    Views:
    527
    Jerry III
    Oct 21, 2003
  2. jc
    Replies:
    3
    Views:
    1,733
  3. jc
    Replies:
    1
    Views:
    1,372
    Neredbojias
    Mar 19, 2008
  4. Replies:
    62
    Views:
    739
    Thomas 'PointedEars' Lahn
    May 26, 2006
  5. Replies:
    1
    Views:
    85
    Randy Webb
    Nov 25, 2006
Loading...

Share This Page