I am following the instructions given on MDN to use <template>
. Slightly different those give in example, my code is:
<template id="template">
<tr>
<td name="id"></td>
<td name="name"></td>
<td name="size"></td>
<td name="Status">
</td>
</tr>
</template>
// ...
const item = document.importNode(template.content, true);
item.getElementsByName("id")[0].textContent = token;
item.getElementsByName("name")[0].textContent = file.name;
item.getElementsByName("size")[0].textContent = file.size;
fileList.appendChild(item);
// ...
However, it appears that item
, of which the __proto__
is DocumentFragment
has no getElementsByName
method.
Is it very confusing for me now that there is getElementById
and querySelector
.
Is there any reason why?
In case related, my browsers are FireFox Quantum 69.0.1 are Chrome Canary 79.0.3918.0.
DocumentFragment
is intended to be very lightweight, it doesn't implement the fullDocument
interface. It doesn't have any of thegetElementsByXXX
methods, justgetElementById
. – RadiculitisgetElementsByName
, either. It's only available on thedocument
element. – RadiculitisquerySelector(All)
would be heavier? Am I misunderstanding "lightweight"? – ToothwortgetElementsByClassName
andgetElementsByTagName
which are not owned byDocumentFragment
. I will edit my question... – Toothwort