I read here that "self Refers to the current window or form".
Self does not seem to refer to the current form in this case:
<form><input type="text" onkeyup="alert(self.foo.value)" name="foo"></form>
However in this case it works (referring to the window):
<form><input type="text" onkeyup="alert(self.document.forms[0].foo.value)" name="foo"></form>
So when would you use the self
DOM property over just window
?
For all windows, the
self
andwindow
properties of awindow
object are synonyms for the current window, and you can optionally use them to refer to the current window. For example, you can close the current window by calling theclose
method of eitherwindow
orself
. You can use these properties to make your code more readable or to disambiguate the property referenceself.status
from a form calledstatus
.