If I create a new HTML element using document.createElement
, but I do not add it to the DOM, is there a way to find it? As this is a method of document
, it seems somewhat logical that it might become property of document
.
Example:
(function(){
document.createElement("a");
})();
console.log(document.getElementsByTagName("a").length); // -> 0
I understand why the above example doesn't work. Is there an alternative?