To obtain an element using a dynamic Id created through ThymeLeaf in jQuery, you can use the following process:
Use ThymeLeaf to render the dynamic Id value on the corresponding HTML element. For example, if you want to create an input field with a dynamic Id, you can use the following ThymeLeaf syntax:
<input type="text" id="field_{{id}}" name="field_{{id}}">
This will render the input field with an Id that includes the value of the id
variable.
To obtain this element in jQuery, you can use the $("#field_" + id)
selector, where id
is the dynamic Id value. For example:
var id = 123;
var $input = $("#field_" + id);
This will obtain the input element with the Id "field_123"
, assuming that ThymeLeaf has rendered the dynamic Id value as 123
.
From here, you can use any jQuery method to manipulate the obtained element, for example, to change its value:
$input.val("New value");
Asked: 2022-09-11 11:00:00 +0000
Seen: 9 times
Last updated: Aug 14 '22