title: How to remove a CSS class from a Wicket component?
body: <p>It's pretty straightforward to dynamically <strong>add</strong> a CSS class to a component in Java code using an <a href="http://wicket.apache.org/apidocs/1.4/org/apache/wicket/behavior/AttributeAppender.html" rel="noreferrer">AttributeAppender</a>:</p>
  
  <pre><code>component.add(new AttributeAppender("class", true, new Model&lt;String&gt;("foo"), " "));
  </code></pre>
  
  <p>Or, if you've extracted the above into an appropriate utility method or class, simply something like:</p>
  
  <pre><code>component.add(WicketUtils.cssClassAppender("foo"));
  </code></pre>
  
  <p><strong>But how can I remove a CSS class?</strong> </p>
  
  <p>You can easily remove <em>all</em> CSS classes by clearing the class attribute altogether:</p>
  
  <pre><code>component.add(new SimpleAttributeModifier("class", ""));
  </code></pre>
  
  <p>...but that is not acceptable if the component has other CSS classes that you do <em>not</em> wish to remove.</p>
  
  <p>Wicket 1.4 (but feel free to post advice specific to later versions too).</p>