Keith said:
<script type="text/javascript"><!--
function grab(o){return
document.all?document.all[o]:document.getElementById?document.getElementById(o):"";}
A more efficient test is to put document.getElementById first, as it
is supported by a wider range of browsers than document.all.
Therefore most browsers will not go to the second test. Rearranging
gives:
return document.getElementById? document.getElementById(o) :
document.all? document.all[o] : "";
When using the style object, you should test to see if it's supported
first, otherwise the user may be presented with an error message that
they have no idea how to remedy.
It doesn't seem to work for me. Would someone mind giving it a try and let
me know if it works for you?
Here is a full page below, there are many different ways to write
this, below is just an example. Over to you.
<html><head><title>play</title></head>
<body>
<script type="text/javascript">
// Given an element id,
// return a reference to the element
function grab(x){
return document.getElementById? document.getElementById(x) :
document.all? document.all[x] : "";
}
// Given an element id and image,
// change the background of the element to the image
function changeBGimg(id, image){
var x = grab(id);
if (x.style){
x.style.backgroundImage = 'url(' + image + ')';
}
}
</script>
<table border="1">
<tr>
<td onclick="
changeBGimg('cellA','a.jpg');
">Click to change background</td>
<td id="cellA"><div style="width:200px; height: 150px;"></div></td>
</tr>
</table>
</body</html>