Lets say I have an object : ${object}
and I have the following form:
<form id="{{'myForm' + object.id}" class="some class" th:action="@{/doSomething}" method="post"> .... </form>
My goal is to set the id = "myForm1" if we assume that the object.id is '1'.
PS: The way I wrote it's working on Angular JS.
The value of the id attribute must be unique within the HTML document. The id attribute is used to point to a specific style declaration in a style sheet. It is also used by JavaScript to access and manipulate the element with the specific id. The syntax for id is: write a hash character (#), followed by an id name.
The id global attribute defines an identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS).
You can use attr('id') in jQuery or the id property (or getAttribute('id') ) on the native DOM element. Show activity on this post. Show activity on this post. You can also use conventional .
You have to use th:id attribute:
<form th:id="'myForm' + ${object.id}" class="some class" th:action="@{/doSomething}" method="post"> // *** Other code here *** </form>
Here is how you can use dynamic id with label:
<th:block th:with="randomId=${#strings.randomAlphanumeric(10)}"> <input type="checkbox" th:id="${randomId}"> <label th:for="${randomId}"></label> </th:block>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With