Dean Kalmantis

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromDean Kalmantis
ToMe
SubjectScript to effect more than one instance
Date29 May 2005 01:22
AttachmentScript that tries to target two elements with the same ID
Hello Mark,

I am looking for some help with a rather simple script, which I cannot take
any further, due to my limited knowledge. I have included an html file with
the actual script and an explanation of what I am looking for. Hope you can
help me. Regards,


Dean Kalmantis
FromMe
ToDean Kalmantis
SubjectRe: Script to effect more than one instance
Date30 May 2005 21:57
Dean,

> effect more than one instance

The simple answer is that you are breaking the rules of HTML. The ID must be
unique to a _single element_. Multiple elements cannot share the same ID.
Give them different IDs, reference them separately, and change them
separately.

If you don't know how many elements you will need to target, you will need
to assign a class to them, use getElementsByTagName to get a reference to
all of the relevant elements, check that they have the correct className,
and if they do, change it to the new one. A bit more difficult than the
first solution, but not impossible.

Hope this helps

Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromDean Kalmantis
ToMe
SubjectRe: Script to effect more than one instance
Date1 June 2005 02:14
> The simple answer is that you are breaking the rules of HTML. The ID must
> be unique to a _single element_. Multiple elements cannot share the same ID.
> Give them different IDs, reference them separately, and change them
> separately.

Thank you Mark for responding to my request. Giving them different IDs was
one of the first things I tried. I succeeded in altering two different
elements within the same cell, but could not change elements outside. Of
course, this is due to my limited knowledge of scripting, but that's where I
am nonetheless.

> If you don't know how many elements you will need to target, you will need
> to assign a class to them, use getElementsByTagName to get a reference to
> all of the relevant elements, check that they have the correct className,
> and if they do, change it to the new one. A bit more difficult than the
> first solution, but not impossible.

Either method would be equally suitable; I just don't know how to get there.
Any resources where I can obtain a model script would be greatly
appreciated.
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.