JSFiddle - React, Tailwind, and code Playground
HTML
<div id="pet-id-1" class="petid">Pet 1</div>
<div id="pet-id-2" class="petid">Pet 2</div>
<div id="pet-id-3" class="petid">Pet 3</div>
<br /><br />
<form action="" method="post" id="pet_form" style="clear: both;">
This would be a hidden field, which submits on the click above.<br />
<input type="text" name="pet_id" id="pet_id" value="" />
</form>
CSS
.petid {
float: left;
display: block;
padding: 15px;
background: #f2f2f2;
margin: 10px;
cursor: pointer;
}
JavaScript
$(document).ready(function() {
$('.petid').click(function() {
var pet_id = $(this).attr('id');
$("#pet_id").val(pet_id);
// You can trigger the submit here.
// $("#pet_form").submit();
});
});