After updating the values in your specific situation, you will observe:
"document".getElementsByTagName("document").onclick = function() {};
1.) Ensure that variable d
is assigned the actual global document reference, not just the string 'document'
var d = window.document;
2.) The method getElementsByTagName
retrieves nodes matching the specified tag name within the DOM node provided; therefore, passing 'document' as a string would search for HTML elements named 'document'. Instead, search for div elements like this:
d.getElementsByTagName("div"); // Retrieves all 'div' elements in the document
3.) When utilizing method names as strings, remember to enclose them in brackets
document[ t ]; // Avoid using document.t as it won't work since t is not a member
4.) Once you have selected the desired nodes, iterate through them to attach event handlers to each element
var d = document.getElementsByTagName("div"),
i = 0,
len = d.length;
for ( ; i < len; i++ ) {
(function() {
// Perform actions with d[i], the current element in the loop
})(i)
}
I trust this explanation proves beneficial! Best wishes.