<?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: Paul Ryan</title>
    <description>The latest articles on DEV Community by Paul Ryan (@paulryan7).</description>
    <link>https://dev.to/paulryan7</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%2F131852%2F0fc36c81-2077-42b1-bd40-45e254bd2115.png</url>
      <title>DEV Community: Paul Ryan</title>
      <link>https://dev.to/paulryan7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/paulryan7"/>
    <language>en</language>
    <item>
      <title>You don't know CSS</title>
      <dc:creator>Paul Ryan</dc:creator>
      <pubDate>Wed, 15 Jul 2020 07:01:37 +0000</pubDate>
      <link>https://dev.to/paulryan7/you-don-t-know-css-4bo8</link>
      <guid>https://dev.to/paulryan7/you-don-t-know-css-4bo8</guid>
      <description>&lt;p&gt;You don't know CSS..&lt;/p&gt;

&lt;p&gt;And neither do I..&lt;/p&gt;

&lt;p&gt;But...&lt;/p&gt;

&lt;p&gt;Let's drop comments below with our favourite CSS gotchas!&lt;/p&gt;

&lt;p&gt;My socials if you ever want to chat code!&lt;br&gt;
| 💂‍♂️ &lt;a href="https://www.instagram.com/paulryancodes/"&gt;Insta&lt;/a&gt; | 👀 &lt;a href="https://twitter.com/PaulRyan7"&gt;Twitter&lt;/a&gt; | 💬 &lt;a href="https://github.com/PaulRyan17"&gt;Github&lt;/a&gt; | 💭 &lt;a href="https://www.linkedin.com/in/paulryan9/"&gt;LinkedIn&lt;/a&gt; | 💥 &lt;a href="https://www.youtube.com/channel/UCf4AtM9ldMfBsO0_bbYWvfw?view_as=subscriber"&gt;Youtube&lt;/a&gt; |📭 &lt;a href="https://www.paulryancodes.com/"&gt;Website&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>discuss</category>
    </item>
    <item>
      <title>The Power of `z-index` Video</title>
      <dc:creator>Paul Ryan</dc:creator>
      <pubDate>Mon, 13 Jul 2020 04:05:56 +0000</pubDate>
      <link>https://dev.to/paulryan7/the-power-of-z-index-video-5d9b</link>
      <guid>https://dev.to/paulryan7/the-power-of-z-index-video-5d9b</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/2RhZveCkxEQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>css</category>
      <category>zindex</category>
      <category>html</category>
    </item>
    <item>
      <title>I finally know the stack data structure.....</title>
      <dc:creator>Paul Ryan</dc:creator>
      <pubDate>Sun, 05 Jul 2020 06:16:39 +0000</pubDate>
      <link>https://dev.to/paulryan7/stack-data-structure-in-javascript-video-3n7l</link>
      <guid>https://dev.to/paulryan7/stack-data-structure-in-javascript-video-3n7l</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/MglgIbtxwoQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Any questions on the above, feel free to contact me on my socials! ❣️&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;💂‍♂️ &lt;a href="https://www.instagram.com/paulryancodes/"&gt;Insta&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;👀 &lt;a href="https://twitter.com/PaulRyan7"&gt;Twitter&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💬 &lt;a href="https://github.com/PaulRyan17"&gt;Github&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💭 &lt;a href="https://www.linkedin.com/in/paulryan9/"&gt;LinkedIn&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💥 &lt;a href="https://www.youtube.com/channel/UCf4AtM9ldMfBsO0_bbYWvfw?view_as=subscriber"&gt;Youtube&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;📭 &lt;a href="https://www.paulryancodes.com/"&gt;Website&lt;/a&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>stack</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Simple SVG drawing effect with `stroke-dasharray` &amp; `stroke-dashoffset`</title>
      <dc:creator>Paul Ryan</dc:creator>
      <pubDate>Sat, 04 Jul 2020 09:33:46 +0000</pubDate>
      <link>https://dev.to/paulryan7/simple-svg-drawing-effect-with-stroke-dasharray-stroke-dashoffset-3m8e</link>
      <guid>https://dev.to/paulryan7/simple-svg-drawing-effect-with-stroke-dasharray-stroke-dashoffset-3m8e</guid>
      <description>&lt;p&gt;If you prefer video format you can &lt;a href="https://www.youtube.com/watch?v=0_mUQBvi7cQ" rel="noopener noreferrer"&gt;head here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hey everyone, I hope you are having a great day!&lt;/p&gt;

&lt;p&gt;Today I am going to show you how to do a simple SVG drawing effect with &lt;code&gt;stroke-dasharray&lt;/code&gt; and &lt;code&gt;stroke-dashoffset&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So take the following SVG path:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"400"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt; &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;"0 0 400 100"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt; 
        &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"m 0 0 h 300"&lt;/span&gt; 
        &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"black"&lt;/span&gt; 
        &lt;span class="na"&gt;pathLength=&lt;/span&gt;&lt;span class="s"&gt;"10"&lt;/span&gt;
        &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"15"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/path&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Visually, that gives us:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fv8alnuuifkgy0vbvs0ul.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fv8alnuuifkgy0vbvs0ul.png" alt="The SVG Path"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So this has a &lt;code&gt;stroke&lt;/code&gt; of &lt;code&gt;black&lt;/code&gt; which is a continuous black line, we can split this up into dashes using &lt;code&gt;stroke-dasharray&lt;/code&gt;.  Our path has a &lt;code&gt;pathLength&lt;/code&gt; of &lt;code&gt;10&lt;/code&gt;, if we set &lt;code&gt;stroke-dasharray&lt;/code&gt; to &lt;code&gt;2&lt;/code&gt;, that means we will split our path into &lt;code&gt;dashes&lt;/code&gt; of &lt;code&gt;2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is how the &lt;code&gt;path&lt;/code&gt; will look.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjvpob2tdkymnugi8iojz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjvpob2tdkymnugi8iojz.png" alt="Dash &amp;amp; Path"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So each &lt;code&gt;dash&lt;/code&gt; has &lt;code&gt;width&lt;/code&gt; of &lt;code&gt;2&lt;/code&gt; and each &lt;code&gt;gap&lt;/code&gt; has a width of &lt;code&gt;2&lt;/code&gt; so &lt;code&gt;10/2 = 5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If we wanted to start on a &lt;code&gt;gap&lt;/code&gt; rather than &lt;code&gt;dash&lt;/code&gt;, we can use the &lt;code&gt;stroke-dashoffset&lt;/code&gt; attribute and set it to a value of &lt;code&gt;2&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw44dqyhuy71zno6n3iwb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw44dqyhuy71zno6n3iwb.png" alt="Path starting with a GAP"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cool, setting the &lt;code&gt;stroke-dashoffset&lt;/code&gt; to the same value as &lt;code&gt;stroke-dasharray&lt;/code&gt; will &lt;strong&gt;offset&lt;/strong&gt; the gap or dash.&lt;/p&gt;

&lt;p&gt;Using this knowledge, we can create a drawing effect.  To achieve this, the first thing we do is set &lt;code&gt;stroke-dasharray&lt;/code&gt; to the same &lt;code&gt;length&lt;/code&gt; of the path which is &lt;code&gt;10&lt;/code&gt;.  Visually this will make no change, but we can use &lt;code&gt;stroke-dashoffset&lt;/code&gt; to start on a &lt;code&gt;gap&lt;/code&gt;, like above we simply set this to the same value of &lt;code&gt;stroke-dasharray&lt;/code&gt; which is &lt;code&gt;10&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"400"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt; &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;"0 0 400 100"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;pathLength=&lt;/span&gt;&lt;span class="s"&gt;"10"&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"m 0 0 h 300"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"black"&lt;/span&gt; &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"15"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/path&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;path&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;stroke-dasharray&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;stroke-dashoffset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will render a blank screen as we are starting on a &lt;code&gt;gap&lt;/code&gt; that is the same &lt;code&gt;length&lt;/code&gt; of our &lt;strong&gt;entire path&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Using some basic CSS, we can create a drawing animation, we simply want to animate the &lt;code&gt;stroke-dashoffset&lt;/code&gt; from the value of &lt;code&gt;10&lt;/code&gt; to the value of &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;path&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;stroke-dasharray&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;stroke-dashoffset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;draw&lt;/span&gt; &lt;span class="m"&gt;2s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt; &lt;span class="n"&gt;forwards&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="n"&gt;draw&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;from&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;stroke-dashoffset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;stroke-dashoffset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This gives us the following:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdtchmy6zpf026ze74w6k.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdtchmy6zpf026ze74w6k.gif" alt="Line Animation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nice!&lt;/p&gt;

&lt;p&gt;Here is the &lt;a href="https://codepen.io/PaulRyan17/pen/eYJVYaQ" rel="noopener noreferrer"&gt;Codepen&lt;/a&gt; you can play around with or fork.&lt;/p&gt;

&lt;p&gt;Any questions on the above, feel free to contact me on my socials! ❣️&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;💂‍♂️ &lt;a href="https://www.instagram.com/paulryancodes/" rel="noopener noreferrer"&gt;Insta&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;👀 &lt;a href="https://twitter.com/PaulRyan7" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💬 &lt;a href="https://github.com/PaulRyan17" rel="noopener noreferrer"&gt;Github&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💭 &lt;a href="https://www.linkedin.com/in/paulryan9/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💥 &lt;a href="https://www.youtube.com/channel/UCf4AtM9ldMfBsO0_bbYWvfw?view_as=subscriber" rel="noopener noreferrer"&gt;Youtube&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;📭 &lt;a href="https://www.paulryancodes.com/" rel="noopener noreferrer"&gt;Website&lt;/a&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>svg</category>
      <category>css</category>
      <category>animation</category>
    </item>
    <item>
      <title>SVG Filters Spotlight Effect</title>
      <dc:creator>Paul Ryan</dc:creator>
      <pubDate>Fri, 03 Jul 2020 02:53:39 +0000</pubDate>
      <link>https://dev.to/paulryan7/svg-filters-spotlight-effect-495m</link>
      <guid>https://dev.to/paulryan7/svg-filters-spotlight-effect-495m</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/BmYFJau_IBo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>svg</category>
      <category>video</category>
      <category>css</category>
    </item>
    <item>
      <title>SVG Filters - Why you so confusing?</title>
      <dc:creator>Paul Ryan</dc:creator>
      <pubDate>Thu, 02 Jul 2020 11:05:16 +0000</pubDate>
      <link>https://dev.to/paulryan7/svg-filters-why-you-so-confusing-5f4f</link>
      <guid>https://dev.to/paulryan7/svg-filters-why-you-so-confusing-5f4f</guid>
      <description>&lt;p&gt;This is originally posted on &lt;a href="https://www.paulryancodes.com/blog/svg-filters-made-easy"&gt;my blog&lt;/a&gt;.  I am going to post the first section here and the rest can be found on my site.  It takes quite some time to format my article to work here, I am doing my best!&lt;/p&gt;

&lt;p&gt;It is no secret just how powerful SVG is, with wide support and a navigable document there is little we can’t do.  SVG filter has been a concept that I never could wrap my head around but this past weekend I made it my mission to learn as much as I could.&lt;/p&gt;

&lt;p&gt;This post will be broken up into two, the first part will focus on the theoretical side while the second part will delve into an example so we can put filters to use (on &lt;a href="https://www.paulryancodes.com/blog/svg-filters-made-easy"&gt;my site&lt;/a&gt;).  A lot of my knowledge (if not all) came from the brilliant Sara Soueidan, so be sure to check out her &lt;a href="https://www.sarasoueidan.com/"&gt;work and articles&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This post presumes you have a basic understanding of SVG &amp;amp; CSS, once you have this you can understand everything discussed.&lt;/p&gt;

&lt;p&gt;Support wise, SVG filters are &lt;a href="https://caniuse.com/#search=SVG%20filter"&gt;pretty well supported&lt;/a&gt;.  Bear in mind that the filter may be applied differently across different browsers.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Filters
&lt;/h2&gt;

&lt;p&gt;I am sure a lot of you out there reading this post have used a CSS filter in some sort of capacity.  Funnily enough, CSS filters actually come from SVG - they are essentially a &lt;strong&gt;less powerful version&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;For those of who you haven’t used CSS filters before they basically work like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cJzEkvJJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o5o3hazqwryl9wfze5a4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cJzEkvJJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o5o3hazqwryl9wfze5a4.png" alt="Paul Ryan Codes Logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Take the above image, we can apply a &lt;code&gt;filter&lt;/code&gt; on this image called &lt;code&gt;blur&lt;/code&gt; which will essentially just blur the image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;blur&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rJyfDXWd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2buabdazvtwdgsb5f1nx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rJyfDXWd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2buabdazvtwdgsb5f1nx.png" alt="Paul Ryan Blurred Codes Logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We could also apply a &lt;code&gt;grayscale&lt;/code&gt; to this image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grayscale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PAjdj_P6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ztxst85kxti3io84tb5b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PAjdj_P6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ztxst85kxti3io84tb5b.png" alt="Paul Ryan GreyScaled Codes Logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is no doubt that CSS filters are easier to use than SVG, but they only offer a fraction of the power so let’s now get into the meat of this post which is &lt;code&gt;SVG Filter&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  SVG Filter
&lt;/h2&gt;

&lt;p&gt;Now that we know what a &lt;code&gt;CSS filter&lt;/code&gt; is, we can focus on the &lt;code&gt;SVG filter&lt;/code&gt;.  Above, we used the &lt;code&gt;blur&lt;/code&gt; function, in SVG they are not called functions, rather they are called &lt;code&gt;primitives&lt;/code&gt;.  This was initially quite confusing to me but it will start making more sense as we delve into using some &lt;code&gt;primitives&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“SVG filters are capable of creating Photoshop-grade effects in the browser” - Sara Soueidan&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are currently &lt;strong&gt;16 primitives&lt;/strong&gt; that we can use, we will use some in this article but I like to use them as I need them rather than try to learn them all at once and have a panic attack! 🤯&lt;/p&gt;

&lt;p&gt;The image we will use for our example is the Paul Ryan Codes logo (vain much?)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cJzEkvJJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o5o3hazqwryl9wfze5a4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cJzEkvJJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o5o3hazqwryl9wfze5a4.png" alt="Paul Ryan Codes Logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using that image, we can have a look at the core syntax for an &lt;code&gt;SVG filter&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"500"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"500"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;filter&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"paulsFilter"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- primitives live in here --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/filter&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;image&lt;/span&gt; &lt;span class="na"&gt;xlink:href=&lt;/span&gt;&lt;span class="s"&gt;"https://assets.codepen.io/1464352/profileimage.png"&lt;/span&gt;    &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"100%"&lt;/span&gt; 
         &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"100%"&lt;/span&gt; &lt;span class="na"&gt;x=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt; &lt;span class="na"&gt;y=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt; 
         &lt;span class="na"&gt;filter=&lt;/span&gt;&lt;span class="s"&gt;"url(#paulsFilter)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/image&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So as you can see the syntax isn’t too alarming, the main thing to note is we gave our filter an &lt;code&gt;id&lt;/code&gt; of &lt;code&gt;paulsFilter&lt;/code&gt; and on our image we set the filter &lt;code&gt;attribute&lt;/code&gt; equal to &lt;code&gt;url(#paulsFilter)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This will give us a blank screen as we have no &lt;code&gt;primitives&lt;/code&gt; in our filter. &lt;/p&gt;

&lt;p&gt;We can now use our first primitive which is &lt;code&gt;feFlood&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The attributes we are going to use from &lt;code&gt;feFlood&lt;/code&gt; are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;flood-color&lt;/strong&gt;  - we can give this a color to flood our image with&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;flood-opacity&lt;/strong&gt; - the opacity of our flood&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;result&lt;/strong&gt; - this is the name we are going to give the output of our primitive&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So putting this all together we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"500"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"500"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;filter&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"paulsFilter"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;feFlood&lt;/span&gt; &lt;span class="na"&gt;flood-color=&lt;/span&gt;&lt;span class="s"&gt;"blue"&lt;/span&gt; &lt;span class="na"&gt;flood-opacity=&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt; &lt;span class="na"&gt;result=&lt;/span&gt;&lt;span class="s"&gt;"FLOOD"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/filter&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;image&lt;/span&gt; &lt;span class="na"&gt;xlink:href=&lt;/span&gt;&lt;span class="s"&gt;"https://assets.codepen.io/1464352/profileimage.png"&lt;/span&gt; 
         &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"100%"&lt;/span&gt; 
         &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"100%"&lt;/span&gt; 
         &lt;span class="na"&gt;x=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt; 
         &lt;span class="na"&gt;y=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt; 
         &lt;span class="na"&gt;filter=&lt;/span&gt;&lt;span class="s"&gt;"url(#paulsFilter)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/image&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will give us the following:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--coKIPj5S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rcpwonlnl1jexmy77rbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--coKIPj5S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rcpwonlnl1jexmy77rbg.png" alt="Paul Ryan Blue Logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can use the &lt;code&gt;feBlend&lt;/code&gt; primitive to blend our image in.  Here are the attributes we will use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;in&lt;/strong&gt; - this is what we will pass into the blend, in our case, this is &lt;code&gt;SourceImage&lt;/code&gt; i.e. the image we are using&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;in2&lt;/strong&gt; - we will also pass in our primitive &lt;code&gt;FLOOD&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;mode&lt;/strong&gt; - there are various modes you can use but we will use &lt;code&gt;color-burn&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;result&lt;/strong&gt; - not necessary but always good practice to have a name for the output&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So putting this all together our final code will look like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"500"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"500"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;filter&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"paulsFilter"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;feFlood&lt;/span&gt; &lt;span class="na"&gt;flood-color=&lt;/span&gt;&lt;span class="s"&gt;"blue"&lt;/span&gt; 
             &lt;span class="na"&gt;flood-opacity=&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt; 
             &lt;span class="na"&gt;result=&lt;/span&gt;&lt;span class="s"&gt;"FLOOD"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;feBlend&lt;/span&gt; &lt;span class="na"&gt;in=&lt;/span&gt;&lt;span class="s"&gt;"SourceGraphic"&lt;/span&gt; 
             &lt;span class="na"&gt;in2=&lt;/span&gt;&lt;span class="s"&gt;"FLOOD"&lt;/span&gt; 
             &lt;span class="na"&gt;mode=&lt;/span&gt;&lt;span class="s"&gt;"color-burn"&lt;/span&gt; 
             &lt;span class="na"&gt;result=&lt;/span&gt;&lt;span class="s"&gt;"BLEND"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/filter&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;image&lt;/span&gt; &lt;span class="na"&gt;xlink:href=&lt;/span&gt;&lt;span class="s"&gt;"https://assets.codepen.io/1464352/profileimage.png"&lt;/span&gt; 
         &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"100%"&lt;/span&gt; 
         &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"100%"&lt;/span&gt; 
         &lt;span class="na"&gt;x=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt; 
         &lt;span class="na"&gt;y=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt; 
         &lt;span class="na"&gt;filter=&lt;/span&gt;&lt;span class="s"&gt;"url(#paulsFilter)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/image&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Our final image after the filter is applied:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6i9hRBh9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yui05hv45gepy1aj5jbu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6i9hRBh9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yui05hv45gepy1aj5jbu.png" alt="Paul Ryan Blue Logo Full"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This may seem like a bit of a silly example, but it gives us the foundation of how we can chain filters together to create a cool output.  &lt;/p&gt;

&lt;p&gt;Complete Codepen can be found &lt;a href="https://codepen.io/PaulRyan17/pen/jOWGQYv"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You can head over to &lt;a href="https://www.paulryancodes.com/blog/svg-filters-made-easy"&gt;my site&lt;/a&gt; for the full post where we will create a &lt;code&gt;spotlight&lt;/code&gt; effect building on the above knowledge.&lt;/p&gt;

&lt;p&gt;Any questions on the above, feel free to contact me on my socials! ❣️&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;💂‍♂️ &lt;a href="https://www.instagram.com/paulryancodes/"&gt;Insta&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;👀 &lt;a href="https://twitter.com/PaulRyan7"&gt;Twitter&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💬 &lt;a href="https://github.com/PaulRyan17"&gt;Github&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💭 &lt;a href="https://www.linkedin.com/in/paulryan9/"&gt;LinkedIn&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💥 &lt;a href="https://www.youtube.com/channel/UCf4AtM9ldMfBsO0_bbYWvfw?view_as=subscriber"&gt;Youtube&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;📭 &lt;a href="https://www.paulryancodes.com/"&gt;Website&lt;/a&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>svg</category>
      <category>css</category>
      <category>filter</category>
    </item>
    <item>
      <title>Harry Potter - Golden Snitch Animation</title>
      <dc:creator>Paul Ryan</dc:creator>
      <pubDate>Mon, 20 Apr 2020 02:33:07 +0000</pubDate>
      <link>https://dev.to/paulryan7/harry-potter-golden-snitch-animation-1m9o</link>
      <guid>https://dev.to/paulryan7/harry-potter-golden-snitch-animation-1m9o</guid>
      <description>&lt;p&gt;Hey guys,&lt;/p&gt;

&lt;p&gt;I created a cool(ish) animation in Codepen which I have shared below.  If you would like me to go into detail on how I made it then just leave a comment.  &lt;/p&gt;

&lt;p&gt;Feel free to use it whatever way you want to!&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/PaulRyan17/embed/bGVeeZw?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Any questions on the above, feel free to contact me on my socials! ❣️&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;💂‍♂️ &lt;a href="https://www.instagram.com/paulryancodes/"&gt;Insta&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;👀 &lt;a href="https://twitter.com/PaulRyan7"&gt;Twitter&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💬 &lt;a href="https://github.com/PaulRyan17"&gt;Github&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💭 &lt;a href="https://www.linkedin.com/in/paulryan9/"&gt;LinkedIn&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💥 &lt;a href="https://www.youtube.com/channel/UCf4AtM9ldMfBsO0_bbYWvfw?view_as=subscriber"&gt;Youtube&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;📭 &lt;a href="https://www.paulryancodes.com/"&gt;Website&lt;/a&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>svg</category>
      <category>greensock</category>
      <category>animation</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Event Delegation - What is it and why should I care?</title>
      <dc:creator>Paul Ryan</dc:creator>
      <pubDate>Fri, 17 Apr 2020 02:10:37 +0000</pubDate>
      <link>https://dev.to/paulryan7/event-delegation-what-is-it-and-why-should-i-care-2e7j</link>
      <guid>https://dev.to/paulryan7/event-delegation-what-is-it-and-why-should-i-care-2e7j</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;It is very common in an interview scenario to be asked to explain event delegation, showing an understanding makes you a much stronger candidate.   Thankfully, it is not too complicated.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Event Listeners
&lt;/h2&gt;

&lt;p&gt;The first area we must venture into is getting an understanding of event listeners.  Event Listeners are essentially something that listens for an event.  Some very common examples are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;keydown&lt;/li&gt;
&lt;li&gt;click&lt;/li&gt;
&lt;li&gt;load&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is some example code that adds an event listener to a &lt;code&gt;div&lt;/code&gt; that has an id of &lt;code&gt;myDiv&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="c1"&gt;// event target&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myDiv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#myDiv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;// adding the listener&lt;/span&gt;
    &lt;span class="nx"&gt;myDiv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;oh my god i've been clicked&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So when our &lt;code&gt;div&lt;/code&gt; gets clicked we fire off the &lt;code&gt;alert&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;One important thing to note is that &lt;code&gt;event listeners&lt;/code&gt; are added on page load, so in the above example when the page is loaded our javascript is executed and tries to find the element with the &lt;code&gt;id&lt;/code&gt; of &lt;code&gt;myDiv&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That all sounds great but what if that element is not available on page load?  Well, then it’s time for event delegation!&lt;/p&gt;

&lt;h2&gt;
  
  
  Event Delegation
&lt;/h2&gt;

&lt;p&gt;So imagine we have a &lt;code&gt;ul&lt;/code&gt; and on the click of a button, a &lt;code&gt;li&lt;/code&gt; is added to our &lt;code&gt;ul&lt;/code&gt;.  When a &lt;code&gt;li&lt;/code&gt; is clicked, we want to remove it from our &lt;code&gt;ul&lt;/code&gt;, the problem is we do not have access to each &lt;code&gt;li&lt;/code&gt; on page load as they simply haven’t been added.  &lt;a href="https://codepen.io/PaulRyan17/pen/qBOZXxO" rel="noopener noreferrer"&gt;Click here&lt;/a&gt; for a Codepen example that will demonstrate this, visually we can also imagine it like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.gyazo.com%2F995a8f940a68aba7d1d9c438c03d03f8.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.gyazo.com%2F995a8f940a68aba7d1d9c438c03d03f8.gif" alt="Adding items to list"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What we want to do is find our if a &lt;code&gt;li&lt;/code&gt; in our list has been clicked.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;html&lt;/code&gt; for the above is the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"my-list"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"addItem()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Add Item&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So when the page is loaded we have access to the &lt;code&gt;my-list&lt;/code&gt; class so that is what we should use as our initial target.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.my-list&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;myList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;removeItem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;removeItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// e.target is the element which dispatched the event&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="c1"&gt;// e.currentTarget is the element which the event listener&lt;/span&gt;
      &lt;span class="c1"&gt;// is added to&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentTarget&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So as commented in the above, when a click happens we get the &lt;code&gt;e&lt;/code&gt; object, this has the property &lt;code&gt;target&lt;/code&gt; which is the element that was clicked i.e. the &lt;code&gt;li&lt;/code&gt; and also has the &lt;code&gt;currentTarget&lt;/code&gt; property which is where our event listener has been added on page load i.e. our &lt;code&gt;ul&lt;/code&gt; element.&lt;/p&gt;

&lt;p&gt;Since we want to remove an &lt;code&gt;li&lt;/code&gt;, we will use the &lt;code&gt;target&lt;/code&gt; property.  To remove the &lt;code&gt;li&lt;/code&gt; we can do the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;removeItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;li&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parentNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We first check that element clicked is indeed a &lt;code&gt;li&lt;/code&gt; and if it is we remove that element!&lt;/p&gt;

&lt;p&gt;That is what event delegation is all about, but we should also discuss &lt;code&gt;event bubbling&lt;/code&gt; a little too.&lt;/p&gt;

&lt;p&gt;Event bubbling is quite simple, it means that when we click on a DOM element that this event will be bubbled the whole way up the DOM.  So in our case when we click on the &lt;code&gt;li&lt;/code&gt;, this is bubbled up to our &lt;code&gt;ul&lt;/code&gt; then to our &lt;code&gt;div&lt;/code&gt; and so on.  &lt;/p&gt;

&lt;p&gt;You can stop this behavior by using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stopPropagation&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In most cases, you won’t need to use it but it is great to know.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why event bother using Event Delegation?
&lt;/h2&gt;

&lt;p&gt;So we don’t have to use event delegation, we could have added an event listener to each &lt;code&gt;li&lt;/code&gt; when it is added but this will add lots of extra code and will increase the number of event listeners on your page by an &lt;code&gt;n&lt;/code&gt; amount (&lt;code&gt;n&lt;/code&gt; being the number of items added).  This will increase the overall memory on your page which will make performance suffer, so it is a very bad idea.  In short, event delegation is great!&lt;/p&gt;

&lt;p&gt;Now go ahead and smash that interview question!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>html</category>
      <category>event</category>
    </item>
    <item>
      <title>Nail your interview by learning Closure (backpack analogy)!</title>
      <dc:creator>Paul Ryan</dc:creator>
      <pubDate>Thu, 16 Apr 2020 04:44:43 +0000</pubDate>
      <link>https://dev.to/paulryan7/nail-your-interview-by-learning-closure-backpack-analogy-3f2k</link>
      <guid>https://dev.to/paulryan7/nail-your-interview-by-learning-closure-backpack-analogy-3f2k</guid>
      <description>&lt;p&gt;'Can you explain Closure?'&lt;/p&gt;

&lt;p&gt;Be prepared to hear this in almost all technical JavaScript interviews, it is one of the core questions they ask you in order to see how well you know JavaScript.  You probably use closure daily when writing JavaScript but the majority of the time this is unknown to you.&lt;/p&gt;

&lt;p&gt;To get into closure, let's look at a regular function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;     &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;helloWorld&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;

     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;helloWorld&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This may not be the most inspirational code but if we delve a little bit deeper there is actually quite a bit going on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;     &lt;span class="c1"&gt;// add the label helloWorld into our global memory with the value of the function&lt;/span&gt;
     &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;helloWorld&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
     &lt;span class="c1"&gt;// now add the label myFunction into our global memory &lt;/span&gt;
     &lt;span class="c1"&gt;// with the value of the helloWorld label&lt;/span&gt;
     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;helloWorld&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="c1"&gt;// call myFunction which will call the helloWorld function and create a new &lt;/span&gt;
    &lt;span class="c1"&gt;//  execution context for helloWorld which will end when the return statement is met&lt;/span&gt;
     &lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you do not know what an &lt;code&gt;execution context&lt;/code&gt; is then &lt;a href="https://alligator.io/js/thread-of-execution/" rel="noopener noreferrer"&gt;head here&lt;/a&gt; where I go in-depth.&lt;/p&gt;

&lt;p&gt;The most important thing to note is that when we call a function, we create a new execution context for that function which we push onto the call stack then when we meet a &lt;code&gt;return&lt;/code&gt; or the last &lt;code&gt;}&lt;/code&gt; we pop if from the call stack.&lt;/p&gt;

&lt;p&gt;Take the example below where the &lt;code&gt;addOne&lt;/code&gt; function is removed from the call stack when it hits a &lt;code&gt;return&lt;/code&gt; statement.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fd33wubrfki0l68.cloudfront.net%2Fdd4557158864a667667bba59e4f901ba181c35aa%2F4a296%2Fimages%2Fjs%2Fthread-of-execution%2F7-o.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fd33wubrfki0l68.cloudfront.net%2Fdd4557158864a667667bba59e4f901ba181c35aa%2F4a296%2Fimages%2Fjs%2Fthread-of-execution%2F7-o.gif" alt="Call Stack Example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With an understanding of the call stack &amp;amp; execution context in place, we can now start with closure.&lt;/p&gt;

&lt;p&gt;Let's take the classic counter example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;     &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
       &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;incrementCounter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
       &lt;span class="p"&gt;}&lt;/span&gt;

       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;incrementCounter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;

     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCoolFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
     &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;myCoolFunction&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// 0&lt;/span&gt;
     &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;myCoolFunction&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
     &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;myCoolFunction&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
     &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;myCoolFunction&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This kinda breaks what we were saying above, how is the &lt;code&gt;counter&lt;/code&gt; value being persisted on each function call?  We create a new execution context for each call so should this value not be essentially reset on each function call?&lt;/p&gt;

&lt;p&gt;The magic is happening on this line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCoolFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;myCoolFunction&lt;/code&gt; is essentially getting two values here - the &lt;code&gt;incrementCounter&lt;/code&gt; function and also the &lt;code&gt;counter&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;Just imagine that the &lt;code&gt;incrementCounter&lt;/code&gt; function has a backpack with the values around it, so &lt;code&gt;myCoolFunction&lt;/code&gt; is assigned the &lt;code&gt;incrementCounter&lt;/code&gt; function and also it's backpack (thank you Will Sentence for this analogy).&lt;/p&gt;

&lt;p&gt;Here is a beautiful image of that:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwyfwtt6lotplzq0cdjdy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwyfwtt6lotplzq0cdjdy.png" alt="Backpack Image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are few different names rather than &lt;code&gt;backpack&lt;/code&gt; which sound a lot more fancy which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Persistent Lexical Scope Referenced Data (rolls off the tongue?)&lt;/li&gt;
&lt;li&gt;Closed Over 'Variable Environment'&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The above definitions will make you sound super smart in an interview, but for understanding closure just think of the backpack!&lt;/p&gt;

&lt;p&gt;To go further in-depth with closure, here is a &lt;a href="https://medium.com/dailyjs/i-never-understood-javascript-closures-9663703368e8" rel="noopener noreferrer"&gt;great article&lt;/a&gt; that also uses the backpack analogy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Any questions on the above, feel free to contact me on my socials! ❣️&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;💂‍♂️ &lt;a href="https://www.instagram.com/paulryancodes/" rel="noopener noreferrer"&gt;Insta&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;👀 &lt;a href="https://twitter.com/PaulRyan7" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💬 &lt;a href="https://github.com/PaulRyan17" rel="noopener noreferrer"&gt;Github&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💭 &lt;a href="https://www.linkedin.com/in/paulryan9/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💥 &lt;a href="https://www.youtube.com/channel/UCf4AtM9ldMfBsO0_bbYWvfw?view_as=subscriber" rel="noopener noreferrer"&gt;Youtube&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;📭 &lt;a href="https://www.paulryancodes.com/" rel="noopener noreferrer"&gt;Website&lt;/a&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>closure</category>
      <category>interview</category>
    </item>
    <item>
      <title>How to draw a heart ♥😻❤❣</title>
      <dc:creator>Paul Ryan</dc:creator>
      <pubDate>Fri, 14 Feb 2020 15:02:17 +0000</pubDate>
      <link>https://dev.to/paulryan7/how-to-draw-a-heart-42jj</link>
      <guid>https://dev.to/paulryan7/how-to-draw-a-heart-42jj</guid>
      <description>&lt;h2&gt;
  
  
  Let's go
&lt;/h2&gt;

&lt;p&gt;Drawing an SVG path couldn't be easier, especially with the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/pathLength"&gt;&lt;code&gt;pathLength&lt;/code&gt;attribute&lt;/a&gt;.  If you are supporting older browsers, click through to the link to see if your browser is supported.&lt;/p&gt;

&lt;p&gt;So let's get an SVG path that we can draw.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MnakWua_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a5js38jey1i7z5w6ao9v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MnakWua_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a5js38jey1i7z5w6ao9v.png" alt="Image of heart"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check out the &lt;a href="https://codepen.io/PaulRyan17/pen/ZEGQMRo"&gt;Codepen&lt;/a&gt; here which has the SVG included.&lt;/p&gt;

&lt;p&gt;The first trick is to add the &lt;code&gt;pathLength&lt;/code&gt; property to our &lt;code&gt;path&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;path ..... pathLength="1" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Doing this makes the animation much easier as we now know the length (i.e. 1).  Before you had to calculate the length which was a massive pain!&lt;/p&gt;

&lt;p&gt;The next thing we need to do is use &lt;code&gt;stroke-dasharray&lt;/code&gt; and &lt;code&gt;stroke-dashoffset&lt;/code&gt;.  We will set both to 1, this essentially makes our SVG disappear so we can draw it.  I don't want to delve into these but you can read about &lt;code&gt;stroke-dashoffset&lt;/code&gt; &lt;a href="https://css-tricks.com/almanac/properties/s/stroke-dashoffset/"&gt;here&lt;/a&gt; and &lt;code&gt;stroke-dasharray&lt;/code&gt; &lt;a href="https://css-tricks.com/almanac/properties/s/stroke-dasharray/"&gt;here&lt;/a&gt;.  Just know you can set &lt;code&gt;pathLength&lt;/code&gt; on any &lt;code&gt;path&lt;/code&gt; that you want to draw so once you set it to &lt;code&gt;1&lt;/code&gt; you can set &lt;code&gt;stroke-dasharray&lt;/code&gt; and &lt;code&gt;stroke-dashoffset&lt;/code&gt; to &lt;code&gt;1&lt;/code&gt; everytime!! 😇&lt;/p&gt;

&lt;p&gt;So in the CSS panel add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;svg path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So the heart has disappeared, that is what we want as we are about to draw it back.&lt;/p&gt;

&lt;p&gt;We need to create an animation that will animate &lt;code&gt;stroke-dashoffset&lt;/code&gt; back to 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes draw {
  from {
    stroke-dashoffset: 1;
  }
  to {
    stroke-dashoffset: 0;
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;One last thing, just add the &lt;code&gt;draw&lt;/code&gt; animation to our path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;svg path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 5s linear alternate infinite;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Our animation is &lt;code&gt;infinite&lt;/code&gt; and also will &lt;code&gt;alternate&lt;/code&gt; so it will draw back and forth.&lt;/p&gt;

&lt;p&gt;Believe it or not but we are now done.  You should have the following:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CWbbrjCH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/9e36b68a388196a7bed24dfd2b4a8596.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CWbbrjCH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/9e36b68a388196a7bed24dfd2b4a8596.gif" alt="Heart drawing"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Complete pen is &lt;a href="https://codepen.io/PaulRyan17/pen/wvaMExg"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Any questions on the above, feel free to contact me on my socials!  &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;💂‍♂️ &lt;a href="https://www.instagram.com/paulryantipp/"&gt;Insta&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;👀 &lt;a href="https://twitter.com/PaulRyan7"&gt;Twitter&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💬 &lt;a href="https://github.com/PaulRyan17"&gt;Github&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💭 &lt;a href="https://www.linkedin.com/in/paulryan9/"&gt;LinkedIn&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💥 &lt;a href="https://www.youtube.com/channel/UCf4AtM9ldMfBsO0_bbYWvfw?view_as=subscriber"&gt;Youtube&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;📭 &lt;a href="https://www.paulryancodes.com/"&gt;Website&lt;/a&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>svg</category>
      <category>javascript</category>
      <category>css</category>
    </item>
    <item>
      <title>🎁🎁 Thread of Execution Visually Explained 🎁🎁</title>
      <dc:creator>Paul Ryan</dc:creator>
      <pubDate>Thu, 13 Feb 2020 22:41:00 +0000</pubDate>
      <link>https://dev.to/paulryan7/thread-of-execution-visually-explained-59hj</link>
      <guid>https://dev.to/paulryan7/thread-of-execution-visually-explained-59hj</guid>
      <description>&lt;p&gt;This is the first in a series of articles on looking at how JavaScript works.  I will try to make it interesting and not bore you as I know this stuff can sometimes get really boring!&lt;/p&gt;

&lt;p&gt;Imagine being a pilot and now knowing how a plane flys, every day we run our JavaScript code but do we know how it runs?&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's talk about the Thread of Execution
&lt;/h2&gt;

&lt;p&gt;Ok, let's bang out some simple code.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bm96tNpm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s4ayan2l76647exapspv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bm96tNpm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s4ayan2l76647exapspv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code above is nothing to get excited about but will serve us well to demonstrate the thread of execution.&lt;/p&gt;

&lt;p&gt;When our JavaScript is executed, it steps through line by line (single-threaded), so in our code above the first line is:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--taWD5w5X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ubxodmh74vemkwth6abr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--taWD5w5X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ubxodmh74vemkwth6abr.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The next question is, what happens when it steps onto this line?  Where does &lt;code&gt;num&lt;/code&gt; get stored?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;num&lt;/code&gt; gets stored in the global memory/execution context, visually it looks like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QukSaFi0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/89dafa3b04d56ff262bd3cf90fc3ba2f.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QukSaFi0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/89dafa3b04d56ff262bd3cf90fc3ba2f.gif" alt="Gif showing animation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So then we move onto the next line.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Du7ukqyO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nw7j6wyf96fk9z1mv32e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Du7ukqyO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nw7j6wyf96fk9z1mv32e.png" alt="Function line"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is important to note that we are declaring a function here and not executing one.  Therefore, we store the function name with the value of the entire function.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EY5ZFMRY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/ac32c4bc720c97c95bcc1ec926545a26.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EY5ZFMRY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/ac32c4bc720c97c95bcc1ec926545a26.gif" alt="Image from Gyazo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;- f -&lt;/code&gt;above is just shorthand for the entire function.&lt;/p&gt;

&lt;p&gt;Now we move onto the next line, some of you may think the next line is the body of the function but since we are only declaring the function and not running it, the next line to run is:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UvXnoAFr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zrtspm31cvmujr9e22z2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UvXnoAFr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zrtspm31cvmujr9e22z2.png" alt="Next line to run"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similar to above, we send the label &lt;code&gt;output&lt;/code&gt; to memory but with no value yet as we must run our function.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PnZPssvK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/b8733aaac9e33b78d5ab0e9adce45033.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PnZPssvK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/b8733aaac9e33b78d5ab0e9adce45033.gif" alt="Saving function label"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now comes the fun part! Actually executing our &lt;code&gt;addOne&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;When a function is executed, it is added to the &lt;code&gt;call stack&lt;/code&gt;.  The &lt;code&gt;call stack&lt;/code&gt; always has &lt;code&gt;global&lt;/code&gt;/&lt;code&gt;main&lt;/code&gt; at the bottom, we now will push on &lt;code&gt;addOne(3)&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2M0YNQqi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/27a387c2d4599d5b501fc9c8d93647cc.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2M0YNQqi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/27a387c2d4599d5b501fc9c8d93647cc.gif" alt="Call stack visualised"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We also create an &lt;code&gt;execution context&lt;/code&gt; for that function.  Any variable declared in the function will be added to the function's execution context.&lt;/p&gt;

&lt;p&gt;The first variables that will be added are the function's arguments, in our case &lt;code&gt;x&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VOsKgzlk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/1585f3c1e4deeb192815fbae8e3c9857.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VOsKgzlk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/1585f3c1e4deeb192815fbae8e3c9857.gif" alt="Image from Gyazo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we move onto the next line and store &lt;code&gt;result&lt;/code&gt; in the &lt;code&gt;execution context&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aoCS43PL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/184ba973b6fa462f52be44d40b6be7b9.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aoCS43PL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/184ba973b6fa462f52be44d40b6be7b9.gif" alt="Image from Gyazo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the next line, we hit the &lt;code&gt;return&lt;/code&gt; keyword which marks the end of a function.  We pop &lt;code&gt;addOne()&lt;/code&gt; from the &lt;code&gt;call stack&lt;/code&gt; and give &lt;code&gt;output&lt;/code&gt; a value which is &lt;code&gt;4&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So first pop &lt;code&gt;addOne&lt;/code&gt; from the &lt;code&gt;call stack&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nbpxzo2d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/1ed1d369e1bee08040c2602323ecc6ef.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nbpxzo2d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/1ed1d369e1bee08040c2602323ecc6ef.gif" alt="Pop from call stack"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now our last step, assigning the value &lt;code&gt;4&lt;/code&gt; to the &lt;code&gt;output&lt;/code&gt; variable.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--489QMFC5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/d96ce811a6b9e52f80708e52d72f7bd5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--489QMFC5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/d96ce811a6b9e52f80708e52d72f7bd5.gif" alt="Image from Gyazo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Donzo
&lt;/h2&gt;

&lt;p&gt;So that is it!  I hope this demonstrates how our code is stepped through.  This was a time-consuming article due to creating all the gifs so let me know if you like them or not.  I know I only touched off the &lt;code&gt;call stack&lt;/code&gt; and &lt;code&gt;execution context&lt;/code&gt; in this article but we will be delving deeper into them in the future.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Any questions on the above, feel free to contact me on my socials! ❣️&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;💂‍♂️ &lt;a href="https://www.instagram.com/paulryancodes/"&gt;Insta&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;👀 &lt;a href="https://twitter.com/PaulRyan7"&gt;Twitter&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💬 &lt;a href="https://github.com/PaulRyan17"&gt;Github&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💭 &lt;a href="https://www.linkedin.com/in/paulryan9/"&gt;LinkedIn&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;💥 &lt;a href="https://www.youtube.com/channel/UCf4AtM9ldMfBsO0_bbYWvfw?view_as=subscriber"&gt;Youtube&lt;/a&gt;
&lt;/th&gt;
&lt;th&gt;📭 &lt;a href="https://www.paulryancodes.com/"&gt;Website&lt;/a&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>code</category>
      <category>beginners</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>The :focus-within CSS pseudo-class</title>
      <dc:creator>Paul Ryan</dc:creator>
      <pubDate>Tue, 11 Feb 2020 14:01:25 +0000</pubDate>
      <link>https://dev.to/paulryan7/the-focus-within-css-pseudo-class-3nhd</link>
      <guid>https://dev.to/paulryan7/the-focus-within-css-pseudo-class-3nhd</guid>
      <description>&lt;p&gt;Recently, while writing an article for CSS Tricks on using skip links I found myself needing to transition a &lt;code&gt;div&lt;/code&gt; into view when an element inside the &lt;code&gt;div&lt;/code&gt; has focus (when a keyboard user tabs onto it).&lt;/p&gt;

&lt;p&gt;Take this &lt;a href="https://codepen.io/PaulRyan17/pen/OJVVdrd"&gt;Codepen&lt;/a&gt; that has a &lt;code&gt;div&lt;/code&gt; which is hidden that contains an &lt;code&gt;a&lt;/code&gt; element.  We want to transition this &lt;code&gt;div&lt;/code&gt; into view when the &lt;code&gt;a&lt;/code&gt; gets focus.  &lt;/p&gt;

&lt;p&gt;Initially, I was going to write JavaScript to do this, but then I found out about the &lt;code&gt;focus-within&lt;/code&gt; pseudo-class.&lt;/p&gt;

&lt;p&gt;So, to transition our &lt;code&gt;div&lt;/code&gt; into view all we need to do is write the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.hidden:focus-within {
  transform: translateY(0%);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That will now give us the following when tabbing our &lt;code&gt;a&lt;/code&gt; into focus.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zw7V-EuF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/b430eda38bd0aa1ee9c2a76389bb3b6c.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zw7V-EuF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/b430eda38bd0aa1ee9c2a76389bb3b6c.gif" alt="Tab Example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And voila! We have now achieved our goal.  &lt;/p&gt;

&lt;p&gt;I hope you learned something and it helps you out!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/PaulRyan17/pen/GRJJzaw"&gt;Complete pen.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;EDIT&lt;/p&gt;

&lt;p&gt;Sebastián Veggiani was kind enough to point out that this isn't fully supported &lt;a href="//caniuse.com/#feat=css-focus-within"&gt;across all browsers&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A polyfill can be &lt;a href="https://github.com/matteobad/focus-within-polyfill"&gt;found here&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Make sure to follow me on &lt;a href="https://www.instagram.com/paulryantipp/"&gt;Instagram&lt;/a&gt; where I share tips, tricks and current stuff I am working on.&lt;/p&gt;

</description>
      <category>css</category>
      <category>javascript</category>
      <category>code</category>
    </item>
  </channel>
</rss>
