title: Remove attributes using HtmlAgilityPack
body: <p>I'm trying to create a code snippet to remove all <code>style</code> attributes regardless of tag using <a href="http://HtmlAgilityPack.codeplex.com">HtmlAgilityPack</a>.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>var elements = htmlDoc.DocumentNode.SelectNodes("//*");
  
  if (elements!=null)
  {
      foreach (var element in elements)
      {
          element.Attributes.Remove("style");
      }
  }
  </code></pre>
  
  <p>However, I'm not getting it to stick? If I look at the <code>element</code> object immediately after <code>Remove("style")</code>. I can see that the style attribute <em>has been removed</em>, but it still appears in the <code>DocumentNode</code> object. :/</p>
  
  <p>I'm feeling a bit stupid, but it seems off to me? Anyone done this using HtmlAgilityPack? Thanks!</p>
  
  <p><strong>Update</strong></p>
  
  <p>I changed my code to the following, and it works properly:</p>
  
  <pre><code>public static void RemoveStyleAttributes(this HtmlDocument html)
  {
     var elementsWithStyleAttribute = html.DocumentNode.SelectNodes("//@style");
  
     if (elementsWithStyleAttribute!=null)
     {
        foreach (var element in elementsWithStyleAttribute)
        {
           element.Attributes["style"].Remove();
        }
     }
  }
  </code></pre>