In C# ASP.NET I am adding a class to an <input>
using:
myInput.Attributes.Add("class","myClass");
At some point I would like to remove the added class (not all classes). Is there an equivalent along the lines of:
myInput.Attributes.Remove("class","myClass");
.Remove()
seems to only accept a key (no pair value). Thank you!
There is nothing built in to manage multiple values in the attribute.
You will have to parse the list, remove the class name and update the attribute.
Something like (untested):
var classes = myInput.Attributes["class"].Split(' ');
var updated = classes.Where(x => x != "classtoremove").ToArray();
myInput.Attributes["class"] = string.Join(" ", updated);
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