Online since 1990 Yes! I started with Gopher. I do modern Web Component Development with technologies supported by **all** WHATWG partners (Apple, Google, Microsoft & Mozilla)
addEventListener doesn't override/write onclick. It is bloated because using onclick is shorter.
Use the ones that do the job for you: javascript.info/introduction-brows...
connectedCallback
Update: see long read Dev.to post: Developers do not connect with the connectedCallback (yet)
Experience yourself; FOO is NOT logged to the console, BAR is logged
Because
connectedCallback()is executed on the OPENING tag (and when DOM nodes are moved around!)So for component1
this.innerHTMLis referencing DOM that does not exist/isn't parsed yet.Many developers, even libraries that make programming Web Components "easier", do
<script defer src="...">to force all their components to load like component 2They don't understand the behavior, thus use
defer. They probably use!importantas well when they do not understand CSS Specificity.LifeCycle Methods:
andyogo.github.io/custom-element-r...
Event listeners
addEventListenerdoesn't override/writeonclick. It is bloated because usingonclickis shorter.Use the ones that do the job for you: javascript.info/introduction-brows...
Thank you! I'll check it out