|
September 21, 2000 Scripting Multiple Elements with the Same ID Tips: September 2000
Yehuda Shiran, Ph.D.
|
|
For certain applications, you may want to have multiple HTML elements with the same ID in a single document. And then, you want to distinguish between them for scripting and other purposes. The following elements, for example, have the same ID, "common":
This is the first common element of the page
The key relevant object in Internet Explorer is
Once you know how many elements you are looking for, you can iterate over them. The following JavaScript script prints the element types of those with
Try it. You can see from the types shown that indeed the two different elements are accessed.
People who read this tip also read these tips: Look for similar tips by subject: |