Open In App

How to check input file is empty or not using JavaScript/jQuery ?

Last Updated : 27 Dec, 2023
Comments
Improve
Suggest changes
3 Likes
Like
Report

Given an HTML document containing an input element, the task is to check whether an input element is empty or not with the help of JavaScript. 

These are the two approaches to check input file is empty or not using JavaScript/jQuery:

Approach 1: Using element.files.length property in JavaScript

To check file is selected or not. If element.files.length property returns 0 then the file is not selected otherwise the file is selected.

 Example: This example implements the above approach. 

Output:

Approach 2: Using element.files.length property in jQuery

To check the file is selected or not. If element.files.length property returns 0 then the file is not selected otherwise file is selected. 

Example: This example implements the above approach. 

Output:


Next Article

Similar Reads