473,657 Members | 2,587 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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')'">Sh ow me information
about topic one.<br>
<input type="checkbox" onclick="flip(' topictwo')'">Sh ow 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 26498
"Noozer" <do*******@me.h ere> wrote in message news:<k2Msd.434 866$nl.289708@p d7tw3no>...
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')'">Sh ow me information
about topic one.<br>
<input type="checkbox" onclick="flip(' topictwo')'">Sh ow 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(cl anSheetame)
{
var re = new RegExp(clanShee tame);
var rules, nRule,
nRules, SS, nSheet = 0,
nSheets = document.styleS heets.length;
for (nSheet; nSheet < nSheets; ++nSheet)
{
SS = document.styleS heets.item(nShe et);
rules = SS.rules;
nRules = rules.length;
for (nRule = 0; nRule < nRules; ++nRule)
{
rule = SS.rules.item(n Rule);
if (re.test(rule.s electorText))
{
for (var a = 1; a < arguments.lengt h; a+=2)
rule.style[arguments[a]] = arguments[a + 1];
return;
}
}
}
}

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

onload = function()
{//keep things in sync
var i = 0,
ipt,
ipts = document.getEle mentsByTagName( '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="toggle class(this)">Sh ow me information
about topic one.<br>
<input type="checkbox" name="toggle" value="topictwo "
onclick="toggle class(this)">Sh ow 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
44324
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 url(../images/homepagebg3.jpg) no-repeat; font:normal 90% Arial, Helvetica, sans-serif; color:#263158;}
4
12728
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
5005
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 data in the text boxes. Then an "update" button saves the data back to the database. What is the best way to change several properties on most of the textbox controls on the form when the "modify" button is clicked? (e.g. make them editible (and...
16
3077
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 create a stand alone method passing the object as an argument: ~~~~ CODE ~~~~ <div id=divTest></div>
16
2025
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 fine using CSS/Javascript, by calling functions that underline and highlight by passing in IDs. The problem is, I do not want to pass in IDs. Currently it has one the TDs to be changed, but I may need to add one for images (to change the
2
22053
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' background='myimg.jpg' width='30'... </tdwhich IE will use to create a Javascript object called 'cell1' with properties of background and width, like so: cell1.background would have a value of 'myimg.jpg' and cell1.width would have a value of 30. I can change the...
2
10826
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 does not post back, nor do I want it to. After the user selects a document in the combo, I want a
7
21814
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
3710
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 element in Firefox.
0
8394
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.