472,989 Members | 3,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

Change CSS Class property using javascript?

I have several tags on a webpage of the same class. If the user clicks a
specific checkbox I'd like to be able to alter the display property of the
class, affecting all objects of that class.

This is an intranet application so we know that javascript will be enabled
and the browser will be IE.

How can I affect all the members of this class? Is there a way I can toggle
the DISPLAY property of a class so all the elements using that class would
be affected?

ie:

default.css file contains the following and is included into the HTLM
document:

.topicone { display:none; }
.topictwo { display:none; }

Relevant section of HTML code:
<input type="checkbox" onclick="flip('topicone')'">Show me information
about topic one.<br>
<input type="checkbox" onclick="flip('topictwo')'">Show me information
about topic two.<br>
<p>Please see the following:</p>
<p> Quick Points </p>
<p class="topicone">This is some information about topic one.</p>
<p class="topictwo">This is some information about topic two.</p>
<p> Details </p>
<p class="topicone">More information about topic one.</p>
<p class="topicone">More information about topic one.</p>
<p class="topictwo">This is some information about topic two.</p>


Jul 23 '05 #1
3 26461
"Noozer" <do*******@me.here> wrote in message news:<k2Msd.434866$nl.289708@pd7tw3no>...
I have several tags on a webpage of the same class. If the user clicks a
specific checkbox I'd like to be able to alter the display property of the
class, affecting all objects of that class.

This is an intranet application so we know that javascript will be enabled
and the browser will be IE.

How can I affect all the members of this class? Is there a way I can toggle
the DISPLAY property of a class so all the elements using that class would
be affected?

ie:

default.css file contains the following and is included into the HTLM
document:

.topicone { display:none; }
.topictwo { display:none; }

Relevant section of HTML code:
<input type="checkbox" onclick="flip('topicone')'">Show me information
about topic one.<br>
<input type="checkbox" onclick="flip('topictwo')'">Show me information
about topic two.<br>
<p>Please see the following:</p>
<p> Quick Points </p>
<p class="topicone">This is some information about topic one.</p>
<p class="topictwo">This is some information about topic two.</p>
<p> Details </p>
<p class="topicone">More information about topic one.</p>
<p class="topicone">More information about topic one.</p>
<p class="topictwo">This is some information about topic two.</p>


Not really enough information, but...IE-only:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>untitled</title>
<style type="text/css">

body {
font: normal 90% verdana;
}
..topicone {
font: normal 80% verdana;
color: #600;
display: none;
}
..topictwo {
font: normal 80% verdana;
color: #060;
display: none;
}

</style>
<script type="text/javascript">

function IE_set_class(clanSheetame)
{
var re = new RegExp(clanSheetame);
var rules, nRule,
nRules, SS, nSheet = 0,
nSheets = document.styleSheets.length;
for (nSheet; nSheet < nSheets; ++nSheet)
{
SS = document.styleSheets.item(nSheet);
rules = SS.rules;
nRules = rules.length;
for (nRule = 0; nRule < nRules; ++nRule)
{
rule = SS.rules.item(nRule);
if (re.test(rule.selectorText))
{
for (var a = 1; a < arguments.length; a+=2)
rule.style[arguments[a]] = arguments[a + 1];
return;
}
}
}
}

function toggleclass(obj)
{
var dval = obj.checked ? 'block' : 'none';
IE_set_class(obj.value, 'display', dval)
}

onload = function()
{//keep things in sync
var i = 0,
ipt,
ipts = document.getElementsByTagName('input');
while (ipt = ipts.item(i++))
if (/toggle/i.test(ipt.name))
ipt.onclick();
}

</script>
</head>
<body>
<form>
<input type="checkbox" name="toggle" value="topicone"
onclick="toggleclass(this)">Show me information
about topic one.<br>
<input type="checkbox" name="toggle" value="topictwo"
onclick="toggleclass(this)">Show me information
about topic two.<br>
<p>Please see the following:</p>
<p> Quick Points </p>
<p class="topicone">This is some information about topic one.</p>
<p class="topictwo">This is some information about topic two.</p>
<p> Details </p>
<p class="topicone">More information about topic one.</p>
<p class="topicone">More information about topic one.</p>
<p class="topictwo">This is some information about topic two.</p>
</form>
</body>
</html>
Jul 23 '05 #2


...lol - I did a S&R to change var 'SSn' to 'nSheet' and it also changed
'classname' to 'clanSheetame' which sounds vaguely Scottish. I am sorry.
:o

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
Rob B wrote:

...lol - I did a S&R to change var 'SSn' to 'nSheet' and it also changed
'classname' to 'clanSheetame' which sounds vaguely Scottish. I am sorry.
:o


And here I was thinking you were being creative. Shazam!

--
Rob
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nathan Given | last post by:
Hello All, I am trying to randomly change the background image of my home page but I can't seem to figure it out. Here is a snippet of my css .... BODY {background:transparent...
4
by: Alexandre Jaquet | last post by:
Hi, I would like to know how can I change a row background color when an user select a row thx
3
by: Tom | last post by:
I am writing a Visual basic .Net database application. There are many forms that first let you select and look at a DB record and then when you click a "modify" button you are allowed to change...
16
by: Java script Dude | last post by:
Creating a method of object (Object.prototype.classOf ...) is not the correct way because of a (as expected) flaw in IE where DOM Elements does not inherit from Object. As a result it is best to...
16
by: Giggle Girl | last post by:
Hi there, I have a nav tree similar to the XP Windows Explorer in behavior. It uses styles to underline a row on mouseover, and change the look of a row when clicked. Currently, it is working...
2
by: Mark | last post by:
IE creates an object of every ID'd HTML tag (so it appears), and each object sets a property for any parameter I set in the tag. For example, my HTML might be: <td id='cell1'...
2
by: Radu | last post by:
Hi, I have a "select" control named "cboSelectScorecardType", defined as <select id="cboSelectScorecardType" size="1" runat="server"> </select> which shows a list of files on my drive. It...
7
by: moondaddy | last post by:
in asp.net 2.0, i have a link buttonand want to change the forecolor in a mouse over event. how can I do this? -- moondaddy@noemail.noemail
15
by: Sunny | last post by:
Hi, I can change the lement opacity in IE using. abc.style.filter = 'alpha(opacity=' + 10 + ')'; But this dont work in firefox, In firefox it throws error. How I can change the opacity of an...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.