Cannot Insert Preloaded Background Image into TR, TD in IE

V

vunet.us

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>
 
E

Evertjan.

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>
 
A

ASM

(e-mail address removed) 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
 
V

vunet.us

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




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>

thank you for inspiration! i just did something wrong...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top