On Aug 15, 7:15 am, "bla...@worldweb.com" <bla...@worldweb.comwrote:
Hi,
I would like to find all elements within my DOM that begin with
"test". Any idea on how I would go about this?
Example Below I would like to return a list of element id's of test1,
test2, test3
<html>
<body>
<div id="spacer">
<div id="test1">Blah</div>
<div id="test2">Blah</div>
</div>
<div id="test3">Blah</div>
</body>
</html>
Use getElementsByTagName('*'), loop through the elements, for those
with an ID, put the IDs (perhaps only the ones of interest) into an
array. Sort, slice, pop, whatever to your hearts content.
Keep an object handy with {id:elementRefernce,...} and use the array
as an index to get back to the elements - or just use getElementById.
Sounds like a bad idea, there must be another way to do whatever it is
you are trying to do.
--
Rob