This post will discuss how to check whether an input text box is empty in JavaScript and jQuery.

1. Using jQuery

To check if the input text box is empty using jQuery, you can use the .val() method. It returns the value of a form element and undefined on an empty collection.

jQuery


HTML



Edit in JSFiddle

 
Using the .length property, you can do like:

Edit in JSFiddle

2. Using JavaScript

With plain JavaScript, you can check the value of the value attribute of the input box to determine whether it is empty.

JS


HTML



Edit in JSFiddle

That’s all about determining whether an input text box is empty in JavaScript and jQuery.