469,315 Members | 1,486 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

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 5351
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.