Bug 138779 - Using document.appendChild to create a new element with ID attribute creates a property / global variable on window
Summary: Using document.appendChild to create a new element with ID attribute creates ...
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Macintosh OS X 10.10
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-16 11:18 PST by Fabio Kenji
Modified: 2014-11-16 14:24 PST (History)
0 users

See Also:


Attachments
a web page with the steps used on the bug report (485 bytes, text/plain)
2014-11-16 11:18 PST, Fabio Kenji
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Fabio Kenji 2014-11-16 11:18:20 PST
Created attachment 241682 [details]
a web page with the steps used on the bug report

It seems that when using the DOM API to create new nodes on a webpage and specifying an ID attribute, a global variable / property on window object is created with the same name as the specified ID.

In the example attached, I am getting a reference to a paragraph in the body of the page. After that, I am creating a new div node and setting its id attribute to 'test_variable'.

In the next lines, I am appending it into the paragraph node reference I had gotten earlier using appendChild(). After that code is run, a new property on window is created, window.test_variable, having the reference to a HTMLDivElementConstructor.
Comment 1 Fabio Kenji 2014-11-16 14:24:02 PST
Nevermind - my mistake, did not not know each element in the page with an ID is accessible through window.