The idea behind this is that you have here a means to address a part (span) of the HTML page and replace its content using Javascript. Javascript code is triggered by the onLoad event. The statement M.innerHTML='Done' is delayed while you respond to the alert().