How to get the input file size in jQuery ? Last Updated : 21 Jun, 2019 Comments Improve Suggest changes Like Article Like Report The task is to get the fileSize when a user uploads it using JQuery. Approach: Display the text Choose file from system to get the fileSize on the screen. Click on the browse button to select the upload file. After selecting a file, the function is called which display the size of the selected file. The function uses file.size method to display the file size in bytes. Example 1: This example adds an event to the input[type=file] element and when user uploads the file, the size of the file prints on screen. html <!DOCTYPE html> <html> <head> <title> How to get the input file size in jQuery ? </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"> </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <p id="GFG_UP" style= "font-size: 15px; font-weight: bold;"> </p> <input type="file" id="File" /> <br><br> <p id="GFG_DOWN" style= "color:green; font-size: 20px; font-weight: bold;"> </p> <script> $('#GFG_UP').text("Choose file from system to get the fileSize"); $('#File').on('change', function() { $('#GFG_DOWN').text(this.files[0].size + "bytes"); }); </script> </body> </html> Output: Before selecting the file: After selecting the file: Example 2: This example adds an event to the input[type=file] element and when user uploads the file, the size of the file prints on screen. This example allows the users to upload file of size lesser than 2MB. html <!DOCTYPE html> <html> <head> <title> How to get the input file size in jQuery ? </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"> </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <p id="GFG_UP" style= "font-size: 15px; font-weight: bold;"> </p> <input type="file" id="File" /> <br><br> <p id="GFG_DOWN" style= "color:green; font-size: 20px; font-weight: bold;"> </p> <script> $('#GFG_UP').text("Choose file from system to get the fileSize"); $('#File').on('change', function() { if (this.files[0].size > 2097152) { alert("Try to upload file less than 2MB!"); } else { $('#GFG_DOWN').text(this.files[0].size + "bytes"); } }); </script> </body> </html> Output: Before selecting the file: After selecting the file(size>2MB): Comment More infoAdvertise with us Next Article Get the height of the hidden element in jQuery P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies jQuery-HTML/CSS Similar Reads How to Reset an <input type="file"> in JavaScript or jQuery Sometimes, you may want to clear a file that has been selected by the user in an <input type="file"> field, without having to reload the entire page. This can be useful if the user wants to reselect a file or if you need to reset a form.There are two main ways to reset a file input in JavaScri 2 min read Get the height of the hidden element in jQuery An HTML element can be hidden with the help of .hide() jQuery function or we can hide easily by making visibility equals hidden in CSS. We can easily find the height of this hidden element in jQuery. There are two kinds of height that are defined with the every HTML element i.e, innerHeight and the 2 min read How to create a File Input using jQuery Mobile ? jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be creating a File Input Area using jQuery Mobile. Approach: Add jQuery Mobile scripts needed for your project. <link rel=âstylesheetâ hr 1 min read How to get file input by selected file name without path using jQuery ? To get the selected file name without the path using jQuery, use the HTML <input type="file"> element. Upon file selection, the jQuery change() method captures the event, and the file name is retrieved using the name property of the event target's files.Syntax:$(selector).change(function(e){}) 2 min read How to Get the Length of a String in Bytes in JavaScript ? In JavaScript, determining the length of a string in characters is straightforward using the length property. However, in many cases, particularly when dealing with file sizes, network protocols, or database storage, you might need to know the length of a string in bytes. This is because characters 3 min read HTML | DOM Input Text size Property The Input Text size Property in HTML DOM is used to set or return the value of the size attribute of an Input Text Field. The size attribute is used to define the width of a text field. Its default value is 20. Syntax: It returns the Input Text size property.textObject.sizeIt is used to set the Inpu 2 min read Like