javascript - Get elements that have not been added to the DOM -
if create new html element using document.createelement
, not add dom, there way find it? method of document
, seems logical might become property of document
.
example:
(function(){ document.createelement("a"); })(); console.log(document.getelementsbytagname("a").length); // -> 0
i understand why above example doesn't work. there alternative?
you're creating elements, without insterting them in dom.
you need store them if want know how many are.
var myelements = []: var elem = document.createelement("a"); myelements.push(elem); myelements.length; // use length needs
Comments
Post a Comment