Forum Moderators: open
<a href="javascript:toggleDisplay(this)">click here</a> I was surprised to see that the object the function received was a reference to the browser window (?). This is in Firefox. If I call the function from
onclick, it works! Am I doing something wrong, or has Javascript behaved this way all along and I just never noticed it before? Thanks in advance for any help!
<div onclick="alert(this)">
// or
myDiv.onclick = function(){ alert(this) }
Meanwhile, an href simply redirects to an 'address' using the javascript protocol. The command could equally well be written in the address bar. The context remains global.
Many commentators are set against using the javascript protocol in hrefs anyway.