[thelist] Re: Finding class

Ben Gustafson Ben_Gustafson at lionbridge.com
Tue Jan 29 12:28:01 CST 2002


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--
[ Picked text/plain from multipart/alternative ]

> >Is there a way using DOM to find elements by their class e.g.(<td
> >id="some_td" class="td_text">) ?
>
> Not directly, though you could do
>
> var x = document.getElementsByTagName('TD');
> for (var i=0;i<x.length;i++)
>   if (x[i].className == 'td_text')
>     do something
>
> >I am trying to modify font sizes depending on the browser used.

Bill,

getElementsByTagName may work in newer versions of IE (I haven't checked),
but you're probably safer with var x = document.all.tags("TD") for including
older versions. For Netscape 6.x and Opera, use getAttribute('class') ==
"td_text" instead of className == "td_text" . className works in Netscape 6,
but getAttribute works in both. For Netscape 4.x, you're on your own ;).

--Ben



More information about the thelist mailing list