JSFiddle - React, Tailwind, and code Playground

by webwakko

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" id="checkit" value="1" /> click me
<input type="text" class="grabme" value="wanted value" />
<input type="text" class="grabme" value="unwanted value" />

JavaScript

$('[id^="checkit"]').change(function() { 
console.log('clicked the checkbox');
var test = $(this).nextAll('input[class^="grabme"]').first().val();
console.log(test);
});