finding all elements with a given class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rick Pasotto

    #1

    finding all elements with a given class

    How do I find all the <div class="xxx"> in a document so that I can
    modify the 'display' property? There's a document.getEle mentById(). Is
    there something like document.getEle mentsByClass() that returns an array?

    --
    You will find that silence or very gentle words are the most exquisite
    revenge for insult. -Judge Hall
    Rick Pasotto rick@niof.net http://www.niof.net
  • PDannyD

    #2
    Re: finding all elements with a given class

    "Rick Pasotto" <rickpasotto@ch i.news.speakeas y.net> wrote in message
    news:slrncjpn97 .cq2.rickpasott o@tc.niof.net[color=blue]
    > How do I find all the <div class="xxx"> in a document so that I can
    > modify the 'display' property? There's a document.getEle mentById(). Is
    > there something like document.getEle mentsByClass() that returns an
    > array?[/color]

    cut-n-pasted from a reply to one of my earlier posts.

    var divs = document.getEle mentsByTagName( 'div');
    if (divs) {
    for (var i = 0; i < divs.length; i++) {
    if (divs[i].className == 'myclass') {
    divs[i].style.color = 'Red';
    }
    }
    }


    Comment

    Working...