I have the following on my interface / webform:
<div id="mydiv" class="forceHeight" runat="server" />
Now I have a condition in my code behind where if a certain situation is true I need to remove the forceHeight
class from this control. I know in C# you can use:
mydiv.CssClass.Replace("forceHeight", "");
I'm not so sure how you do this using VB? Intellisense doesn't offer me this option?
Any ideas anyone?
The syntax for Removing CSS classes to an element:removeClass(class_name);
To remove a class from an element, you use the remove() method of the classList property of the element.
To remove all CSS classes of an element, we use removeClass() method. The removeClass() method is used to remove one or more class names from the selected element.
Remove a class style from a selection Select the object or text you want to remove the style from. In the HTML Property inspector (Window > Properties), select None from the Class pop‑up menu.
If a control has several classes you can remove one of those classes by editing the class string. Both of these methods require assigning an ID to the HTML element so that you can target it in the code behind.
<asp:Panel ID="mydiv" CssClass="forceHeight class2 class3" runat="server" />
VB.NET
mydiv.CssClass = mydiv.CssClass.Replace("forceHeight", "").Trim()
C#
mydiv.CssClass = mydiv.CssClass.Replace("forceHeight", "").Trim();
OR using html generic control
<div id="mydiv" class="forceHeight class2 class3" runat="server" />
VB.NET
mydiv.Attributes("class") = mydiv.Attributes("class").Replace("forceHeight", "").Trim()
C#
mydiv.Attributes["class"] = mydiv.Attributes["class"].Replace("forceHeight", "").Trim();
Optional Trim
to remove trailing white space.
VB.NET
mydiv.Attributes.Remove("class")
C#
mydiv.Attributes.Remove("class");
This will remove all CSS classes from the div with ID="mydiv"
Me.mydiv.Attributes("class") = ""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With