What am I doing wrong here? Why am I not able to select the link
within the template?
Found 3 template(s)
Found 0 link(s)
Found 0 link(s)
Found 0 link(s)
const templates = [...document.getElementsByTagName('template') || []]
console.log(`Found ${templates.length} template(s)`)
templates.map((template) => {
const links = [...template.getElementsByTagName('link') || []]
console.log(`Found ${links.length} link(s)`)
})
Example HTML:
<template></template>
<template>
<link/>
</template>
<template></template>
2
Answers
I was missing
content
You need to use
property to correctly access to template html content.