[Javascript] Swapping an Image

Peter-Paul Koch gassinaumasis at hotmail.com
Fri Jul 20 06:46:30 CDT 2001


>That's right, I used to assign names to my images. What is the story on
>names and id's?

It's a long and complicated story. Initially the HTML Specs didn't recognize 
NAME as a valid attribute for IMG, although the browsers did and it was in 
use for a few years already.

There was a lot of boring discussion about this problem three years ago and 
it ended in W3C adding NAME to the HTML 4.01 spec, so you could officially 
use it without any validation problems.

>Are they both officially supported as standard HTML?

Yes, though NAME is deprecated and ID is recommended. Some browsers don't 
support ID, though, so NAME is your safest choice.

>Is it likely to cause any problems to replace <image id="something" with 
><image name="something"?

I don't think so, but it depends on how the browser sees 'getElementById'. 
Does ID mean NAME, too? I'm not sure.

You don't need to use ID for a simple image swapping script, 
document.images['the_name'] still works in all browsers, including the 
newest ones. I always use NAMEs and the old faithful document.images array 
for my mouseovers and don't bother with IDs and getElementById.

>Can names be freely interchanged with id's anyplace?

Theoretically, yes, but I wouldn't be surprised if there were some problems 
somewhere.

ppk


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




More information about the Javascript mailing list