empty a input field jquery code example
Example 1: clear input jqueyr
$('#inputButtonID').val('');
Example 2: how can prevent the empty input in jquery
$('#form').submit(function() {
if ($.trim($("#email").val()) === "" || $.trim($("#user_name").val()) === "") {
alert('you did not fill out one of the fields');
return false;
}
});
Example 3: empty the value of an input in jquery
$('#field').val('');
Example 4: clear value input jquery
<body>
<form method="" action="">
<input type="text" name="email" class="input" />
<input type="submit" value="Sign Up" class="button" />
</form>
</body>
<script>
$(document).ready(function() {
$(".input").val("Email Address");
$(".input").on("focus", function() {
$(".input").val("");
});
$(".button").on("click", function(event) {
$(".input").val("");
});
});
</script>