I have an input and a label. I want to show the label when the user types anything in the input box. However, as you can see in the snippet (or on jsFiddle), the first character you type in the input box is ignored and you need to type another one in order for the value to not be empty.
$('input').on('change paste keydown', function(event) {
var inputID = event.target.id;
var value = $('#' + inputID).val();
$('#' + inputID + 'Label').css('visibility', 'visible');
if (value == ''){
$('#' + inputID + 'Label').css('visibility', 'hidden');
}
})
#input1Label { visibility: hidden; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label id='input1Label'>Label</label>
<input id='input1'>