finding all elements with a given class

R

Rick Pasotto

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?
 
P

PDannyD

Rick Pasotto said:
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.className == 'myclass') {
divs.style.color = 'Red';
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top