<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: TechMeta</title>
    <description>The latest articles on DEV Community by TechMeta (@techmeta402).</description>
    <link>https://dev.to/techmeta402</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F377085%2F9159b11c-d194-4b59-8550-8ca5679f973b.png</url>
      <title>DEV Community: TechMeta</title>
      <link>https://dev.to/techmeta402</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/techmeta402"/>
    <language>en</language>
    <item>
      <title>Creating Web Components using Vanilla JS</title>
      <dc:creator>TechMeta</dc:creator>
      <pubDate>Fri, 01 May 2020 00:05:06 +0000</pubDate>
      <link>https://dev.to/techmeta402/creating-web-components-using-vanilla-js-450c</link>
      <guid>https://dev.to/techmeta402/creating-web-components-using-vanilla-js-450c</guid>
      <description>&lt;p&gt;Hello everyone, this is my first 'dev.to' post. I will be going over, step by step, how I created two web components that I used on my personal website.&lt;/p&gt;

&lt;h1&gt;
  
  
  Building a Web Component
&lt;/h1&gt;

&lt;p&gt;To begin I created two separate files, one was an html file (index.html) and the other was a JavaScript file (skillCard.js). &lt;/p&gt;

&lt;h2&gt;
  
  
  HTML
&lt;/h2&gt;

&lt;p&gt;The HTML is very straightforward: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--huXWwcPD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xqosn2lxalpuoqb3ykw6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--huXWwcPD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xqosn2lxalpuoqb3ykw6.png" alt="Alt Text" width="880" height="319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The (skill-card) tag is what I worked on in the JavaScript file. &lt;br&gt;
Another important part of the HTML code is referencing the JavaScript file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ViMBzI0T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zdtt5wwvhqmm8akqynre.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ViMBzI0T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zdtt5wwvhqmm8akqynre.png" alt="Alt Text" width="582" height="44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript
&lt;/h2&gt;

&lt;p&gt;After I created the HTML document, I went ahead and created the JavaScript file.&lt;br&gt;
The first thing I did was create a class for my custom element. Inside the class I created a constructor and also used the "super();" method to call the constructor of the HTMLElement that is being extended. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rA5aXva---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6pfietw6ins6qzarkvwb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rA5aXva---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6pfietw6ins6qzarkvwb.png" alt="Alt Text" width="634" height="114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside the constructor, I also created a "shadow DOM".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M-gf7GsE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zacbdezyren8tjzb95ro.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M-gf7GsE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zacbdezyren8tjzb95ro.png" alt="Alt Text" width="880" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, I defined the custom element at the bottom of the JavaScript file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oxQlf3en--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/g1gjmtg451pva2men8d9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oxQlf3en--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/g1gjmtg451pva2men8d9.png" alt="Alt Text" width="702" height="48"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above the class, I created the new element and that is where I am able to set the inner HTML to whatever I want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N4hDcn-1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/il52f0tez3b85mfiw3xq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N4hDcn-1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/il52f0tez3b85mfiw3xq.png" alt="Alt Text" width="702" height="1402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is where I can control the structure and styling of the information.&lt;/p&gt;

&lt;h2&gt;
  
  
  Completed Web Components
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Complete HTML for skill-card&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_Fke0TI_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/hviv1o4g6lyu7mpmq92x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_Fke0TI_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/hviv1o4g6lyu7mpmq92x.png" alt="Alt Text" width="880" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Complete JavaScript for skill-card&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hapAxDT5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3j5xgvt4tjvm38pfom6r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hapAxDT5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3j5xgvt4tjvm38pfom6r.png" alt="Alt Text" width="694" height="1564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To view the changes as you go, I opened the HTML file in the Chrome browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Finished Web Component&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--prX3EDRF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/928zhb794y3416x9022g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--prX3EDRF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/928zhb794y3416x9022g.png" alt="Alt Text" width="880" height="787"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The other web component was similar, except it did not use an icon. It is a basic project card where I describe my work and also provide a link to my project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Complete HTML for project-card&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K80Wcla6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y14l59kvs0jcvw66pdoc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K80Wcla6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y14l59kvs0jcvw66pdoc.png" alt="Alt Text" width="880" height="184"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Complete JavaScript for project-card&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H8HpyHN---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cwty8s74qpg0fa1ge7hq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H8HpyHN---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cwty8s74qpg0fa1ge7hq.png" alt="Alt Text" width="752" height="1626"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Finished Web Component&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_sKbEBxE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1vbr79ac8c02gzcv7w3c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_sKbEBxE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1vbr79ac8c02gzcv7w3c.png" alt="Alt Text" width="880" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Resources
&lt;/h2&gt;

&lt;p&gt;This is a link to a YouTube video that I used to help me get started: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=PCWaFLy3VUo"&gt;YouTube Video&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webcomponents</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
