Within the connectedCallback()
method of my custom element the textContent
is returned as an empty string.
Essentially my code boils down to the following...
class MyComponent extends HTMLElement{
constructor() {
super()
console.log(this.textContent) // not available here, but understandable
}
connectedCallback() {
super.connectedCallback() // makes no difference if present or not
console.log(this.textContent) // not available here either, but why?!
}
}
customElements.define('my-component', MyComponent);
And the HTML...
<my-component>This is the content I need to access</my-component>
From reading about connectedCallback()
it sounds like it's called once the element has been added to the DOM so I would expect that the textContent property should be valid.
I'm using Chrome 63 if it helps...
Aucun commentaire:
Enregistrer un commentaire