Skip to content
Advertisement

Tag: web-component

Adding an event within a WebComponent

I want to create a Web Component. I use a ShadowDom and after generating a list I want to add a click Event to each element of the list. But I wonder how to access the list. Neither the document nor the template shows me the items after a querySelect. My question: How can I access the generated list within

Why does customElements.upgrade appear to not upgrade this custom element?

I have a situation similar to the example below: from a template element, I clone a node tree containing custom elements. One custom element is passed data during initialization, represented here by the line infobox.setData(getData()). The function I use to pass the data (setData) is added by my custom class, so I make sure the custom element is upgraded before

Why I can not call method of WebComponent?

I wonder why I cannot call a method defined in web-component if I attached this component via .append instead of using tag name inside the template. Below I am providing few examples. One is not working(throwing an error). I wonder why this first example is throwing this error. Example 1 In this example, I am creating a web-component inside my

JavaScript: refer to anonymous class static variable

Following this google tutorial on web components, and I like the way the author uses an anonymous class in the customElements.define function call, as it avoids even more brackets when creating an immediately invoked function call. I am using a static class variable to store the template element, so it’s not queried every time the custom tag is instantiated. The

Difference between HTML template content and innerHTML

Say I have an HTML <template> tag that I define and select as follows: What is the difference between these properties of the template: Answer Contrary to innerHTML, content returns a document fragment, and so you get immediate access to the DOM without an intermediate conversion to and from a string. Here is the difference in use:

Advertisement