Email conversation
From | Dean Kalmantis |
To | Me |
Subject | Script to effect more than one instance |
Date | 29 May 2005 01:22 |
Attachment | Script 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
From | Me |
To | Dean Kalmantis |
Subject | Re: Script to effect more than one instance |
Date | 30 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/
From | Dean Kalmantis |
To | Me |
Subject | Re: Script to effect more than one instance |
Date | 1 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.