[thelist] [DHTML] Elements with the same ID

Erik Mattheis gozz at gozz.com
Tue Mar 18 23:37:31 CST 2003

It's not an id if it's not unique!

Maybe you should do something like:

<p id="foo1">text</p>
<p id="foo2">more text</p>

and find them like:

function getFoo() {
	tags = document.getElementsByTagName('p');
	for (i = 0; i < tags.length; i++) {
		if (tags[i].attributes.id.value.substr(0,3) == 'foo') {
			alert('i got foo!');

On Tuesday, March 18, 2003, at 10:47 PM, Mark M wrote:

> Quick question.
> If you have multiple elements that have the same id in a page.. can 
> you access
> them all through the same ID? or does the system automatically create 
> an array
> you can loop through under that ID?
> The reason I ask is because we have a series of images on a page that 
> we want to
> hide/display on a single click... if we give them all the same ID it 
> makes life easy.
> Thanks in advance,
Erik Mattheis
GoZz Digital
Flash and ColdFusion Development
Minneapolis, MN

More information about the thelist mailing list