473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to find all elements starting with <text>

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>

Aug 14 '07 #1
2 4838
bl****@worldweb.com wrote on 14 aug 2007 in comp.lang.javascript:
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>
Nice school assignmant, methinks.
Any idea on how I would go about this?
Sure, but it seeme better you explore the possiblilities yourself.

Advice: use a loop.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 14 '07 #2
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

Aug 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: seberino | last post by:
Tuples are defined with regards to parentheses ()'s as everyone knows. This causes confusion for 1 item tuples since (5) can be interpreted as a tuple OR as the number 5 in a mathematical...
3
by: Derek Fountain | last post by:
When is the use of <xsl:text>blah blah</xsl:text> necessary? I'm finding that, although it's used religously in the book I'm learning from, if I miss it out, the output is just the same.
4
by: Carsten Kraft | last post by:
Hello Newsgroup, I think this is easy for you: I want to save the data line by line into an string array. eg. Text file: Array Line 1 Line1
2
by: Hoss | last post by:
Hi guys, The framework of my page is an aspx page with a header and a footer. The header is a menu system and depending on what you select there different ascx pages are loaded into the middle...
2
by: Paul Verbelen | last post by:
I have a file with topics. I like to copy them in another file but want to have some blank lines between the different topics. I use <xsl:text> element with as data some blank lines to perform...
11
by: Ole Nielsby | last post by:
First, sorry if this is off-topic, not strictly being a C++ issue. I could not find a ng on numerics or serialization and I figure this ng is the closest I can get. Now the question: I want...
14
by: Michael | last post by:
Since the include function is called from within a PHP script, why does the included file have to identify itself as a PHP again by enclosing its code in <?php... <?> One would assume that the...
5
by: ajos | last post by:
hi frnds, this is the way i ve written--> <html:text name="bdgtmastForm" property="publicity_code" size="5" maxlength="5"> but its giving me an error which seems irrelevent.. type Exception...
10
by: test9991014 | last post by:
Hi all, I have an <input type=texttag that is taking up too much space vertically. It's in a <tdthat has a fixed height, and I've set the height value in the <input>'s style to be 10px, less...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.