javascript - jQuery .unload() doesn not work, but .load() does -


i'm new jquery forgive me ignorance.

i'm trying load , unload content dynamically using jquery.

.load() works reason can't same thing .unload(). i'm not sure doing wrong. care enlighten me? thank :)

this code

$( document ).ready( function() {     $( 'a.dynamicload' ).click( function( e ) {         e.preventdefault();   // prevent browser following link         e.stoppropagation();  // prevent browser following link          $( '.content-wrap' ).load('projects/project1.html');     });       $('#back').click(function(){         $( '.content-wrap' ).unload('projects/project1.html');     });  }); 

the unload function in jquery not used purpose. used set window unload event happen, such when exiting page.

https://api.jquery.com/unload/

the unload event sent window element when user navigates away page. mean 1 of many things. user have clicked on link leave page, or typed in new url in address bar. forward , buttons trigger event. closing browser window cause event triggered. page reload first create unload event.

if need clear element, setting innerhtml nothing sufficient.

$( '.content-wrap' ).html(''); 

see http://jsfiddle.net/dm7hhnjc/

with respect op, scope of load , unload in jquery lead astray accident naming scheme inherently confusing unless familiar window.onunload already


Comments