Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
25
rated 0 times [  32] [ 7]  / answers: 1 / hits: 19167  / 12 Years ago, sun, april 29, 2012, 12:00:00

I'm looking to (dynamically) obtain a list of HTML elements the browser is currently aware of, such as HTMLPreElement, HTMLSpanElement etc. These objects are global, i.e.



console.log('HTMLPreElement' in window);  //=> true


So I thought I'd be able to use getOwnPropertyNames like this:



console.log(Object.getOwnPropertyNames(window));


to obtain the full list of global properties (MDN states that this returns both enumerable and non-enumerable properties).



Using the above, I get an array with around 70 property nanes. But, it doesn't include objects like HTMLPreElement - only HTMLElement. I also tried:



console.log(Object.getOwnPropertyNames(window.Window.prototype));


which brings back a bigger list (including addEventListener etc) but again, no HTMLPreElement.



So, where the heck do these HTML{Tag}Element objects reside?


More From » properties

 Answers
21

In Firefox, it seems to be the behavior of elements that their global object is not added unless explicitly requested as a global variable or property. Perhaps Firefox lazy loads them into the environment so that they don't consume memory unless they're actually needed.



It seems that they do not show up when simply requesting the keys of the global object via Object.getOwnPropertyNames unless they've first been explicitly referenced as described above.



http://jsfiddle.net/mBAHm/


[#85898] Friday, April 27, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
trayvon

Total Points: 35
Total Questions: 117
Total Answers: 88

Location: Guernsey
Member since Tue, Jul 6, 2021
3 Years ago
;