How to download File Using JavaScript/jQuery ? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 9 Likes Like Report The ability to download files directly from a website is an essential feature for many web applications. Whether you're providing documents, images, or other data, enabling users to download files seamlessly enhances their experience and ensures they can access the content offline. This article provides a comprehensive guide on how to implement file downloads using JavaScript and jQuery, complete with a detailed folder structure to help you locate and manage your files efficiently.Approach:Create an anchor tag link on the normal HTML page. We want to download a file when we click on an anchor tag link(Download this file). html <!DOCTYPE html> <html> <head> <title> Download File Using JavaScript/jQuery </title> </head> <body> <h1> Download File Using JavaScript/jQuery </h1> <a id="link" href="#"> Download this file </a> </body> </html> Provide with the below JavaScript Code:$(document).ready(function () { $("#link").click(function (e) { e.preventDefault(); window.location.href = "File/randomfile.docx"; });});// Note: url= your file pathNote: Replace the above URL with your file path. Implementation and Folder structure is as shown below.Example: html <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script> </head> <body> <h1> Download File Using JavaScript/jQuery </h1> <h3> For Downloading, Click on the below link. </h3> <a id="link" href="no-script.html"> Download this file </a> <script> $(document).ready(function () { $("#link").click(function (e) { e.preventDefault(); window.location.href = "File/randomfile.docx"; }); }); </script> </body> </html> Output:jQuery is an open source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous with it's philosophy of “Write less, do more". You can learn jQuery from the ground up by following this jQuery Examples. Create Quiz Comment S spyviku Follow 9 Improve S spyviku Follow 9 Improve Article Tags : JavaScript jQuery-Misc JavaScript-Misc Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like