P
Patient Guy
I have this in a document:
<body onload="a_function(this);">
In an (external) script file, I define a_function() as follows:
function a_function(obj)
{
// surprise errant coding here
var docImages = obj.parentNode.getElementsByTagName("img");
// more code follows
}
When I change the 'body' tag to the following, it works:
<body onload="a_function(document.body);">
Much to my surprise, the 'obj' parameter is NOT the 'body' node of the
document (i.e., document.body). The object 'obj' is in fact an instance
of a 'window' class (the window object). This behavior is true in Firefox
(as seen in Venkman) and in MS Internet Explorer (as guessed by an error
in script).
Two and a half questions:
1. Why is 'obj' the window object and not document.body object (node)?
2. Is it proper to use lowercase arguments in the getElementsByTagName()
method? Suggested failsafe workarounds?
<body onload="a_function(this);">
In an (external) script file, I define a_function() as follows:
function a_function(obj)
{
// surprise errant coding here
var docImages = obj.parentNode.getElementsByTagName("img");
// more code follows
}
When I change the 'body' tag to the following, it works:
<body onload="a_function(document.body);">
Much to my surprise, the 'obj' parameter is NOT the 'body' node of the
document (i.e., document.body). The object 'obj' is in fact an instance
of a 'window' class (the window object). This behavior is true in Firefox
(as seen in Venkman) and in MS Internet Explorer (as guessed by an error
in script).
Two and a half questions:
1. Why is 'obj' the window object and not document.body object (node)?
2. Is it proper to use lowercase arguments in the getElementsByTagName()
method? Suggested failsafe workarounds?