I use JQuery 1.11 and want to act on all ids beginning with partitions0.instances0.natures
and ending with typeCle
like : id="partitions0.instances0.natures0.typeCle"
. Then I will affect to those, the same value than my selected element. But my problem here is on the selector.
I've tried many things like $('[id^='+instanceId'][id$=typesCle]')
with or without double quotes but can't find the right answer by now. The error is Uncaught SyntaxError: Invalid or unexpected token
All the jquery code :
var instanceId = $(this).attr("id");
var natureId = $(this).attr("id");
var valeur = $(this).prop('value');
natureId = natureId.replace("typesCle", "nature").replace(/\./g, '\\\\.');
$('[id^='+ natureId +'][id$=typesCle]').each(){
this.val(valeur);
}
I've also replaced the variable by its value to check and I 've the same error message :
$('[id^=partitions0\\.instances0\\.nature][id$=typesCle]').each(){
console.log(valeur);
this.val(valeur);
}
The html code :
<div class="col-sm-6">
<select th:field="*{partitions[__${rowPartitionStat.index}__].instances[__${rowInstanceStat.index}__].typesCle}" class="form-control modRepInstance">
<option th:each="typeCle : ${allTypesCle}"
th:value="${typeCle}" th:text="${typeCle}">...</option>
</select>
</div>