JSFiddle - React, Tailwind, and code Playground

HTML

<div id="test22">
    <span id="content22">Click to add the value</span>
    <input type="hidden" id="hidden22" value="hello">
</div>

<div id="test33">
    <span id="content33">Click to add the value</span>
    <input type="hidden" id="hidden33" value="world">
</div>

<input type="text" id="show">

JavaScript

$(document).ready(function(){ 
    $("[id^=content]").click(function(event){
        var digit = this.id.replace("content","");
        $("#show").val($("#hidden" + digit).val());
    });
});