JSFiddle - React, Tailwind, and code Playground
by koh_edwin
HTML
<textarea id="sds"> Apple
Banana
Grape
Orange</textarea>
<input type="hidden" id="sdh" />
<div id="popup" title="Poof"></div>
CSS
#sds {
display: none;
}
JavaScript
var sds = $("#sds").val();
var sda = sds.split("\n");
var sdi = "";
$.each(sda, function(k, s) {
sdi += "<input type='text' id='sd" + k + "' value='" + s + "' />" +
"<button id='button" + k + "'>Click Me</button><br />";
$("#sdh").val(k);
});
$("#popup").html(sdi);
// select all buttons inside #popup, that have an id starting by "button"
$("#popup button[id^=button]").click(function() {
var i = parseInt($(this).attr('id').replace('button', ''));
alert(i); // Test to see what returns for the value of i.
$("#sd" + i).val("Clicked button " + i);
});