Thymeleaf: how to use conditionals to dynamically add/remove a CSS class

后端 未结 10 1076
無奈伤痛
無奈伤痛 2020-12-12 15:04

By using Thymeleaf as template engine, is it possible to add/remove dynamically a CSS class to/from a simple div with the th:if clause?

Nor

10条回答
  •  [愿得一人]
    2020-12-12 15:32

    If you just want to append a class in case of an error you can use th:errorclass="my-error-class" mentionned in the doc.

    
    

    Applied to a form field tag (input, select, textarea…), it will read the name of the field to be examined from any existing name or th:field attributes in the same tag, and then append the specified CSS class to the tag if such field has any associated errors

提交回复
热议问题