471,859 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,859 software developers and data experts.

GetElementById vs. IE7

Hello all,

I have some simple JavaScript code that changes an image based on some user action (i.e. pushing a button).
I sniff the broiwsers and, in case of IE5+, I use GetElementById and then change the object.src, pointing to the proper gif or jpg.
The code is:

if ( document.getElementById ) // IE5+ & Gecko
{
if ( document.getElementById( id ).innerHTML != null )
{
document.getElementById( id ).innerHTML.src = url;
}
}
else if ( document.getElementById ) // IE5+ & Gecko
{
if ( document.getElementById( id ) != null )
{
document.getElementById( id ).src = url;
}
}
else if (document.all) // IE4
{
if ( document.all[ id ] != null )
{
document.all[ id ].src = url;
}
}
else // Netscape 4
{
if ( document.images[ id ] != null )
{
document.images[ id ].src = url;
}
}

Very basic JavaScript... should it be...
In fact, it works fine with IE5 or IE6 and Netscape, but does not work with IE7.
Is there anything regarding GetElementById and IE7 ?
Or is my piece of script wrong ?

Pelase, help... :-|
May 7 '07 #1
3 5408
Hello all,

I have some simple JavaScript code that changes an image based on some user action (i.e. pushing a button).
I sniff the broiwsers and, in case of IE5+, I use GetElementById and then change the object.src, pointing to the proper gif or jpg (selected by the "url" variable, previously assigned according to the user action, e.g. button on/off).
The code is:

if ( document.getElementById ) // IE5+ & Gecko
{
if ( document.getElementById( id ).innerHTML != null )
{
document.getElementById( id ).innerHTML.src = url;
}
}
else if ( document.getElementById ) // IE5+ & Gecko
{
if ( document.getElementById( id ) != null )
{
document.getElementById( id ).src = url;
}
}
else if (document.all) // IE4
{
if ( document.all[ id ] != null )
{
document.all[ id ].src = url;
}
}
else // Netscape 4
{
if ( document.images[ id ] != null )
{
document.images[ id ].src = url;
}
}

Very basic JavaScript... should it be...
In fact, it works fine with IE5 or IE6 and Netscape, but does not work with IE7.
Is there anything regarding GetElementById and IE7 ?
Or is my piece of script wrong ?

Please, help... :-|
May 7 '07 #2
r035198x
13,262 8TB
Hello all,

I have some simple JavaScript code that changes an image based on some user action (i.e. pushing a button).
I sniff the broiwsers and, in case of IE5+, I use GetElementById and then change the object.src, pointing to the proper gif or jpg.
The code is:

if ( document.getElementById ) // IE5+ & Gecko
{
if ( document.getElementById( id ).innerHTML != null )
{
document.getElementById( id ).innerHTML.src = url;
}
}
else if ( document.getElementById ) // IE5+ & Gecko
{
if ( document.getElementById( id ) != null )
{
document.getElementById( id ).src = url;
}
}
else if (document.all) // IE4
{
if ( document.all[ id ] != null )
{
document.all[ id ].src = url;
}
}
else // Netscape 4
{
if ( document.images[ id ] != null )
{
document.images[ id ].src = url;
}
}

Very basic JavaScript... should it be...
In fact, it works fine with IE5 or IE6 and Netscape, but does not work with IE7.
Is there anything regarding GetElementById and IE7 ?
Or is my piece of script wrong ?

Pelase, help... :-|
Please do not double post.

Threads merged
May 7 '07 #3
acoder
16,027 Expert Mod 8TB
You can't have
Expand|Select|Wrap|Line Numbers
  1. document.getElementById( id ).innerHTML.src;
Get rid of that 'if' code block.

In any case, if the first code block is executed, it's not going to execute the second one which checks for the same thing.
May 7 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by PaulB | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.