I am learning Web Components. To grab a template, I needed to do this:
<template>
<div>The sky is blue</div>
</template>
<script>
var tmpl = (document.currentScript||document._currentScript).ownerDocument.querySelector('template');
Instead of:
var tmpl = document.querySelector('template');
I don't understand this part at all: (document.currentScript||document._currentScript).ownerDocument
What is currentScript
, what is ownerDocument
? What is the purpose? Why does it work. Note that the template code I have shown above gets pulled in via the link
element.
Note, this is related to this post and this article. I AM just trying to understand the keywords, I don't have any particular problem in mind.