JSFiddle - React, Tailwind, and code Playground

HTML

<div>
    <h3>Working </h3>
    <input id="input1" type="text" value="" />
    <input class="button" type="button" value="Add value" />
</div>

<div>
    <h3>Not working</h3>
    <input id="options[input2]" type="text" value="" />
    <input class="button" type="button" value="Add value" />
</div>

JavaScript

$('.button').click(function(){
    var fieldID = $(this).prev().attr("id");
	$('#' + fieldID).val("hello world");
});