HTML Question

Thymeleaf: Is there something similar to th:classappend to remove a class value?

I'm trying to show one alert in some screen with this code:

<div id="errorDiv" class="alert alert-danger hidden">
<label id="errorLabel"></label>
<button type="button" class="close" data-hide="alert" aria-hidden="true">&times;</button>
</div>


By default, errorDiv div is hidden because it has the value hidden in the class attribute (I'm using bootstrap).

I would like to find in Thymeleaf something similar something similar to th:classappend but instead of adding a value, removing the 'hidden' value in the class attribute to show the div.

Answer

I think you can use conditional css class include with elvis operator, something like:

<div id="errorDiv" class="alert alert-danger"  th:classappend="*{isError}?:'hidden'">
    <label id="errorLabel"></label>
    <button type="button" class="close" data-hide="alert" aria-hidden="true">&times;</button>
</div>

this should append 'hidden' to the class attribute only if *{isError} is null.

see http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#default-expressions-elvis-operator