finerrecliner@gmail.com wrote:
Quote:
note: if i use the line document.onclick=click(e);
it won't work correctly, and will only call the click function when the
user clicks the button (rather than anywhere on the page).
Well that assignment calls the click function with an argument e (which
is probably not defined) and the result of that function call is
assigned to the document.onclick property.
Quote:
document.onclick=click; //why does this line work?!
An event handler is a function and your assigment correctly assigns a
function, your click function, to the document.onclick property. The
browser then, when a click event occurs, calls that function, it is not
your code that has to call the function. And in the case of Mozilla the
browser passes in an event object as the first argument of the function.
For IE you need to use the window.event object as it does not pass in
the event object when it calls an event handler.
--
Martin Honnen
http://JavaScript.FAQTs.com/