Using thymeleaf variable in onclick attribute Using thymeleaf variable in onclick attribute spring spring

Using thymeleaf variable in onclick attribute


thymeleaf 3.0.10 th:onclickthymeleaf variable not working

This should work:

th:attr="onclick=|upload('${gallery}')|" 


I solve this issue with this approach:

th:onclick="|upload('${command['class'].simpleName}', '${gallery}')|"


This should work:

<button th:onclick="'javascript:upload(' + ${gallery} + ')'"></button>