Html Agility Pack - New HtmlAttribute

Tom Bowen picture Tom Bowen · Aug 23, 2013 · Viewed 7.5k times · Source

Using Html Agility Pack in C# I have a node I'd like to add an attribute to.

Currently the node is an <li> element with no attributes and I'd like to add a class to it of "active".

It looks like the best thing to use would be node.Attributes.Add(attrClass)

Where attrClass is a HtmlAttribute of class="active".

However if I try to define a new HtmlAttribute I get an error stating that it doesn't have any constructors. Eg HtmlAttribute attrClass = new HtmlAttribute();

Is there something wrong with my Html Agility Pack reference, or am I doing something incorrectly?

Is there another method I could use to achieve my goal?

Answer

I4V picture I4V · Aug 23, 2013
node.Attributes.Add("class","active");