Amy wrote:
let say i have an id range Ie. test1, test2, test3 ...
How do i call all of them at a time ? I cant use getElementbyId for
sure ...
If you know the number of elements, you can always try a for-loop:
for (i = 0; i < MAX; i++) {
e = document.getElementById('test' + i);
if (e == null) continue;
// do something with e
}
Another option is to give every element the same _name_, you can query
those:
// returns array of objects named 'test'.
t = document.getElementsByName('test');
If you know the type of the elements you can query
getElementsByTagName() in the same way as you query the getelements. You
can check with startsWith whether its the right object:
t = document.getElementsByTagName('input');
for (i = 0; i < t.length; i++) {
if (t.id.startsWith('test')) {
// do somethnig
}
}
If all else fails you'll have to walk the DOM tree recusivly, or if you
only target IE, you can use the all[] array to walk through all elements.
Good luck,
Vincent