<az******@gmail .com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Here is a handy function that lets multiple browsers perform this:
Put this in the <HEAD>:
<script type="text/javascript"><!--
function grab(o){return
document.all?do cument.all[o]:document.getEl ementById?docum ent.getElementB yId(o):"";}
//--></script>
Instead of feature testing everytime you execute grab(), one can define
grab once at the beginning of the page and then reasonably assume that
the feature support will not change in that user agent for the lifetime
of the script:
<script type="text/javascript">
var grab;
if (document.getEl ementById)
{
grab = function(o)
{
return document.getEle mentById(o);
}
}
else if (document.all)
{
grab = function(o)
{
return document.all[o];
}
}
else
{
grab = function()
{
return { style:{} };
}
}
</script>
Then when you want to grab an object by its ID attribute:
<script type="text/javascript"><!--
grab("tablecell ").style.backgr oundImage="url( images/image1.jpg)";
//--></script>
Since your code makes the assumption that grab() is returning an object
that contains a property named -style-, but in some cases your version
of grab() returns an empty string, the line above may generate an error
on user agents which support neither document.getEle mentById nor
document.all.
In cases where the user agent supports neither document.getEle mentById
nor document.all, my solution returns an object with a -style- property
which can other arbitrary properties assigned to it.
Note that I'm not 100% convinced this is an adequate solution, but since
we tend to assume that the Node returned by document.getEle mentById and
document.all supports a -style- property, it seems reasonable to return
an object that has one even when we don't obtain a valid Node.
--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ -
http://jibbering.com/faq