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

Posted on 2006-06-25
Last Modified: 2012-06-22
How can I do something like:

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

<div class="foo">bar</div>
Question by:mnb93
  • 2

Expert Comment

ID: 16978220
Changing the class?

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

document.getElementById("foo").className = "yar";
LVL 15

Accepted Solution

justinbillig earned 250 total points
ID: 16983400
I think what your looking for is here in this link


Expert Comment

ID: 16984330
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.
LVL 15

Expert Comment

ID: 16984378
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jQuery Scroll To Top 5 38
Hide Table in merge 3 32
Javascript Urgent help (Need help to disable event handler) 8 43
jQuery force form POST 7 48
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question