By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,045 Members | 1,389 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,045 IT Pros & Developers. It's quick & easy.

finding all elements with a given class

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

--
You will find that silence or very gentle words are the most exquisite
revenge for insult. -Judge Hall
Rick Pasotto ri**@niof.net http://www.niof.net
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Rick Pasotto" <ri*********@chi.news.speakeasy.net> wrote in message
news:sl************************@tc.niof.net
How do I find all the <div class="xxx"> in a document so that I can
modify the 'display' property? There's a document.getElementById(). Is
there something like document.getElementsByClass() that returns an
array?


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

var divs = document.getElementsByTagName('div');
if (divs) {
for (var i = 0; i < divs.length; i++) {
if (divs[i].className == 'myclass') {
divs[i].style.color = 'Red';
}
}
}
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.