jQuery | unload() Method Last Updated : 05 May, 2025 Comments Improve Suggest changes Like Article Like Report The unload() method in jQuery is used to perform unload event when the user try navigates away from current webpage.The event can be triggered when user changes the dynamic state of the page for example user clicked on link to leave the page, a new URL is typed in the address bar etc. the unload method should only be use on window object. it specifies what will happen when a unload event occurs. Syntax:$(selector).unload(function)Parameters This method accepts only one and required parameter described below: Function:It is an required parameter which is used to specify the function to run when the unload event is triggered. Example-1: This example describes the triggering of unload event when you click on link. html <!DOCTYPE html> <html> <head> <title> jQuery unload() Method </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> </head> <body style="text-align:center;"> <br/> <br/> <br/> <h1 style="color:green;"> GeeksForGeeks </h1> <p>When you click <a href="https://www.geeksforgeeks.org/"> Go to geeks</a>, or close the window, an alert box will be triggered.</p> <!-- Script to illustrates unload() method --> <script> $(document).ready(function() { $(window).unload(function() { alert("you are leaving from page"); }); }); </script> </body> </html> Output:Before click anywhere:After clicking on link or try to navigating away from the pageExample-2: This example describes the triggering of unload event when you click on link. html <!DOCTYPE html> <html> <head> <title> jQuery unload() Method </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <style> h1 { border: 1px solid black; height: 100px; padding-top: 35px; background: green; color: white; } </style> </head> <body style="text-align:center;"> <h1>GeeksForGeeks</h1> <!-- Script to illustrates unbind() method --> <script> $(document).ready(function() { $(window).unload(function() { alert("you are leaving from page"); }); }); </script> <p>When you click <a href= "https://www.geeksforgeeks.org/community/">GeeksForGeeks</a>, or close the window, an alert box will be triggered.</p> </body> </html> Output:Before click anywhere:After clicking on link or try to navigating away from the pageNote:The working of unload event depeandent on browsers.The unload() method was removed in version 3.0.The unload() method was deprecated in jQuery version 1.8. Comment More infoAdvertise with us Next Article jQuery | unload() Method A ashishsaini3 Follow Improve Article Tags : Web Technologies JQuery jQuery-Methods Similar Reads jQuery | unbind() Method The unbind() Method is an inbuilt method in jQuery which is used to remove any selected event handlers. This method can be used to remove particular event handler, or stop specific functions. It works on any event handler using an event object. Note: If no parameters are provided, the method works o 2 min read jQuery undelegate() Method The jQuery undelegate() method is an inbuilt method that is used to remove the specified event handler from the selected element. Syntax: $(selector).undelegate(selector, event, function)Parameters: This method accepts three parameters as mentioned above and described below: selector: It is an optio 2 min read jQuery | off() Method The off() Method in jQuery is used to remove event handlers attached with the on() method. The off() method brings a lot of consistency to the API and it replace unbind(), die() and undelegate() methods. Syntax: $(selector).off(event, selector, function(eventObj), map) Parameter: This method accepts 2 min read jQuery remove() Method The remove() method in JQuery is used to remove all the selected elements including all the text. This method also remove data and all the events of the selected elements. Syntax: $(selector).remove()Return Value: It will return all the data of the selected elements deleted. Example 1: Input: $("p") 2 min read jQuery | get() Method In jQuery .get() method loads data from the server by using the GET HTTP request. This method returns XMLHttpRequest object. Syntax $.get( url, [data], [callback], [type] ) Parameters url : String containing the URL at which request is to be sent data : This is an optional parameter that represents 2 min read Like