tags:

views:

381

answers:

2

I'm working on a web app that uses javascript to change the classes of 3 div's depending on what buttons the user has pressed.

Is it possible to get the value of the current class of a div?

I tried adding runat="server" to the div tag and then using...

thediv.Attributes.CssStyle.Value

... to get the value of the class.

But it is returning nothing.

Any ideas?

+1  A: 

Don't use a DIV. Use

 <asp:Panel ID="TestDiv" runat="server" CssClass="foo"></asp:Panel>

and then you can get/set the class with

var myClass= TestDiv.CssClass;

Or

TestDiv.CssClass = "bar";

As has been mentioned, using a jquery class selector would accomplish the same thing without the need for postback.

Chuck
A: 

You can get it this way:

Dim thediv as HtmlGenericControl = 
    DirectCast(Page.FindControl("divid"), HtmlGenericControl);
thediv.Attributes("class");
Joseph
Me.divid.Attributes["class"] (VB)
Martin