Link to home
Start Free TrialLog in
Avatar of mnb93
mnb93

asked on

document.getElementById('foo').style.display = 'none'; FOR classes

How can I do something like:

document.getElementById('foo').style.display = 'none';
but for classes:

eg.
<div class="foo">bar</div>
Avatar of pD_EO
pD_EO

Changing the class?

<div class="foo" id="foo">bar</div>

document.getElementById("foo").className = "yar";
ASKER CERTIFIED SOLUTION
Avatar of justinbillig
justinbillig

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
why dont you just assign id="foo" to the <div> tag.
e.g.  <div id="foo">bar</div>

Instead of a class as classes are used for CSS.
well what I think he is trying to accomplish is .. there are multiple items that use the foo class, what he wants to do is programatically hide all items that have the foo class without having to iterate though all the items on the page