Remove an html attribute

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Remove an html attribute

Galak
Hi everybody

is there a way to tell Thymeleaf to remove an html attribute?
a kind of th:remove-attr="attrName1,attrName2" (with attrNames being all available html attributes)

e.g.:
<img src="/myImage.png" th:src="@{/myImage}" alt="My Image" th:remove-attr="alt" />
the alt attribute would be removed when processing the template...

Thank you for your answers
Geraud

Reply | Threaded
Open this post in threaded view
|

Re: Remove an html attribute

Emanuel
Administrator
There isn't a specific attribute to do this, but I did some tests and found that using the th:attr attribute and specifying an empty argument will delete the attribute.  eg:

<div id="blah" th:attr="id=''"></div>

Thymeleaf will end-up removing the id attribute because it's blank.  Works for the alt attribute too, although alt is a required attribute for XHTML and HTML5 markup.