Document object write method works differently when used inside the function and when outside. When inside of function it replaces the entire elements on the document with the string specified in it but when outside the function, just below the element the content is written. Why do this happen?
function foo(){document.write("Maizere")}
element.onclick=foo
When the event occurs everything on the document is replaced with the string specified in the write method.
document.write().