JSFiddle - React, Tailwind, and code Playground
by David Thomas
HTML
<form action="" method="get">
<fieldset>
<label for="fieldName">This is a label:</label>
<input type="text" name="fieldName" id="fieldName" />
<div class="error"></div>
</fieldset>
</form>
JavaScript
$(document).ready(
function(){
$('form').submit(
function(){
var $field = $('input[name=fieldName]').attr('id');
var $message= 'This field needs something else. Such as...';
$('#'+$field).addClass('invalid').siblings('.error').text($message).show();
return false;
});
}
);