Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getElementById 1

Status
Not open for further replies.

gapla

Programmer
Dec 15, 2003
37
ES
Hi, i'm new to using DOM
How could i retrieve the content of a span without id ?
As in
<span class="blabla">
I know how to get it if it had an id, for example
getElementById("myHeader")
 
You could use a function to get elements by their className, such as the one in this handy FAQ I wrote for the JavaScript forum:

How can I get all elements by their class (frequently called getElementsByClass or getElementsByClassName) (faq216-6104)

or you could use:

Code:
var theSpan = document.getElementsByTagName('span')[someIndex];

if the span was always in the same place in the markup.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top