[thelist] DOM: Getting elements with class="foo"?

Matt Warden mwarden at gmail.com
Wed Nov 23 11:56:24 CST 2005


On 11/23/05, Frank <lists at frankmarion.com> wrote:
>
> I've got a table with certain rows that have a class that point to
> display:none; I want to toggle visiblility with a link. Some rows have the
> class, others, none. How do I go about accessing the rows based on having
> the class name?
>
> After than I imagine it's just a matter of looping over them and change the
> class.

var trs = document.getElementsByTagName('TR');
for (var i=0; i<trs.length; i++) {
    if (trs[i].className && trs[i].className.indexOf('yourclass') >= 0) {
        // go for it
    }
}

See also:

(a) http://www.onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html
(b) http://dean.edwards.name/my/cssQuery/

as they might make this easier for you.


--
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the thelist mailing list