jquery - Find input whose name attribute value has [somedigit] in it -
i've got several divs inside inputs this:
<div class="executor"> <input type="hidden" name="task.executors[0].id"/> <input type="hidden" name="task.executors[0].name"/> <input type="hidden" name="task.executors[0].jobtitle"/> </div> <div class="executor"> <input type="hidden" name="task.executors[1].id"/> <input type="hidden" name="task.executors[2].name"/> <input type="hidden" name="task.executors[3].jobtitle"/> </div>
i need selector this: find inputs name contains executors[somedigit]
. somedigit
part makes hard me. need regex this?
edit: seem have missed important part. need change executors[somedigit]
executors[2]
. need me replace somedigit
one.
edit2: why need this. suppose there 100 of such divs. last div going contain hidden inputs name contains task.executors[99]
. now, let's 87'th div gets removed. there 99 divs , inputs inside last div must have names changed task.executors[99]
task.executors[98]
. need indexes correct model valid model.
you can use attribute contains selector along concatenation of required number:
var somenum = 2; $('[name*="executor['+ somenum +']"]')
demo:
$(function(){ var somenum = "0"; $('[name*="executor['+ somenum +']"]').val('abv') })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <div class="executor"> <input type="text" name="task.executor[0].id"/> <input type="text" name="task.executor[0].name"/> <input type="text" name="task.executor[0].jobtitle"/> </div> <div class="executor"> <input type="text" name="task.executor[1].id"/> <input type="text" name="task.executor[2].name"/> <input type="text" name="task.executor[3].jobtitle"/> </div>
Comments
Post a Comment