CSS class dynamic change

C

czuvich

All,

I was wondering if it was possible to change a css class on a page load
(somehow). Basically, I am wanting to say this:

<div id="myclass" class="a javascriptfunction">

Is this possible? I want the javascript function to set the class name.
If so, could someone please post a snippet? If not.. here's my
scenario... perhaps there is a better alternative.

I have a checkbox that when checked it changes the stylesheet for a
dynamic popup effect.

function Swap(element)
{
if(document.getElementById(element).className == 'open')
{
document.getElementById(element).className= 'closed';
}
else
{
document.getElementById(element).className= 'open';
}
}

Me.ckbAdvanced.Attributes.Add("OnClick",
"JavaScript:Swap('advancedoptionsmenu');")

This works fine. However, I then click a submit button that does a
postback. Lo and behold, I lose my css class since I initialize it in
the html to 'closed' (automatically sets it to closed). I want to keep
my css class as 'open' during a postback. How can I accomplish this?
 
B

bruce barker \(sqlwork.com\)

you code behind should do this. if not, then the client code needs to save
the value in a hidden field, and reset it on <body onload> based on th
hiddden field value.

-- bruce (sqlwork.com)
 
C

czuvich

bruce said:
you code behind should do this. if not, then the client code needs to save
the value in a hidden field, and reset it on <body onload> based on th
hiddden field value.

-- bruce (sqlwork.com)

Thanks for the reply. But I was wondering how do I get the code behind
to do this? I set the div to runat=server so that I can access it in
the code behind, but then I lose my dynamic menu drop in the javascript
(unless I am doing something wrong). If I can save it in a hidden
field, then what is the syntax for changing the class on the fly in the
html? I am struggling with the correct syntax. Thanks for the help!
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top