Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To obtain an element using a dynamic Id created through ThymeLeaf in jQuery, you can use the following process:

  1. 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.

  2. 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");