I am pretty new to jQuery so I have a problem with this.
I am trying to check if input is empty by jQuery. I have this script:
$('#submit').click(function(){
if($.trim($('#username').val()) == ''){
alert('Input can not be left blank');
}
});
Thanks for reply.
Answer
Check the length property to determine if it's empty:
if ($.trim($('#username').val()).length > 0) {
// not empty
}
Edit:
Removed white spaces $.trim
No comments:
Post a Comment