Reputation: 774
I have the following jquery and want to check if the text box is empty before the code is run:
<script type="text/javascript">
$(document).ready(function () {
if ($("#FNameTB").val().length < 0) {
$("input#FNameTB").labelify({ labelledClass: "greylabel" });
}
</script>
but its not working.
Upvotes: 6
Views: 14201
Reputation: 25776
Length will never be less than 0.
if ( $("#FNameTB").val().length === 0 )
You can even add in a trim() to be thorough
if ( $("#FNameTB").val().trim().length === 0 )
Upvotes: 13
Reputation: 755141
Try the following
if ($('#FNameTB').val() === '') {
// It's empty
}
Upvotes: 0