Both document.getElementsByTagName('div') and document.querySelectorAll('div') return NodeList collection. The only difference is that first method returns live-collection and second one - a static one.
The question is - is there any opportunity to distinguish one object from another only via inspecting these objects (i.e - not trying to add/remove some items to test "liveness")?
thanks in advance
The NodeList
interface is agnostic of its dead or live status.
interface NodeList {
Node item(in unsigned long index);
readonly attribute unsigned long length;
};
It only contains a property length
, and a method item
so I'm afraid it's currently not possible to determine if an object is live without manipulating the DOM and seeing the effects.
a=document.querySelectorAll('a');
b=document.getElementsByTagName('a');
a.toString() == "[object NodeList]"
b.toString() == "[object HTMLCollection]"
(in FF/Chrome)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With