<?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>Forem: Athul Anil Kumar</title>
    <description>The latest articles on Forem by Athul Anil Kumar (@athul7744).</description>
    <link>https://forem.com/athul7744</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%2F364336%2Ffb2b0aca-903c-4c79-9559-4e2b743373d1.jpeg</url>
      <title>Forem: Athul Anil Kumar</title>
      <link>https://forem.com/athul7744</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/athul7744"/>
    <language>en</language>
    <item>
      <title>JavaScript Basics : How to retrieve an element from the DOM? </title>
      <dc:creator>Athul Anil Kumar</dc:creator>
      <pubDate>Thu, 14 May 2020 10:17:05 +0000</pubDate>
      <link>https://forem.com/athul7744/javascript-basics-how-to-retrieve-an-element-from-the-dom-5g2p</link>
      <guid>https://forem.com/athul7744/javascript-basics-how-to-retrieve-an-element-from-the-dom-5g2p</guid>
      <description>&lt;p&gt;JavaScript can do many wonderful things, and one of them is &lt;a href="https://www.w3schools.com/js/js_htmldom.asp"&gt;DOM&lt;/a&gt; (Document Object Model) manipulation. To manipulate a DOM element you need to access the corresponding DOM object and that is what this post is all about. Lets get right into it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Needle in a Haystack
&lt;/h2&gt;

&lt;p&gt;There are many methods to get an element from the DOM. We will go from the slowest to fastest methods based on performance.&lt;/p&gt;

&lt;h4&gt;
  
  
  Accessing By ID
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementByID&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is the fastest method to retrieve an object from the DOM. When an element is added to the DOM with an id, it is stored as a global variable in the document tree object. (You can find more about how that design choice happened &lt;a href="https://stackoverflow.com/a/3434388"&gt;here&lt;/a&gt;, it's a funny story!). This is also why DOM element IDs need to be unique. When you call this method passing the ID of the element you need as an argument it instantly refers this global store and returns the DOM object.&lt;/p&gt;

&lt;h4&gt;
  
  
  Accessing by Class Name or Tag Name
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementsByTagName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;    &lt;span class="c1"&gt;//using tag name&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementsByClassName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;//using class name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;document.getElementsByTagName&lt;/code&gt; takes a HTML tag name (like &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;,&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;,&lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;,&lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; etc) as an argument and returns elements having that HTML tag type. &lt;code&gt;document.getElementsByClassName&lt;/code&gt; takes a classname as an argument and returns elements having that classname. As the name suggests these two functions retrieve multiple DOM elements at once and hence perform slower than &lt;code&gt;document.getElementByID&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Accessing using Selectors
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;    &lt;span class="c1"&gt;//returns the first element&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//returns all elements&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;These are very powerful functions to retrieve DOM elements. They take &lt;a href="https://www.w3schools.com/cssref/css_selectors.asp"&gt;CSS selectors&lt;/a&gt; as an argument to retrieve the elements. This allows you to mix and match selectors to find the exact element(s) you need. &lt;code&gt;document.querySelector&lt;/code&gt; returns the first matched element, while &lt;code&gt;document.querySelectorAll&lt;/code&gt; returns all matched elements. As functionality and capability increases so does required time. Hence these are the slowest of the native DOM element retrieval functions.&lt;/p&gt;

&lt;h4&gt;
  
  
  Bonus Method : Accessing using jQuery
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;jQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;jQuery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;jQuery is a very useful library of functions which makes it easier to query the DOM and traverse elements. It has a lot of built in functions to retrieve elements and manipulate them. It has the functionality of all the native functions and more, but the major drawback is the time required for every operation. jQuery is much more slower than native JS in doing equivalent tasks. You can find more about jQuery &lt;a href="https://api.jquery.com/"&gt;here&lt;/a&gt;.&lt;/p&gt;




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

&lt;p&gt;In this post we have seen several different methods for accessing DOM elements using ID, tagName, className, selectors and by using jQuery. Hope you liked it. Thanks for reading through. &amp;lt;3&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Part 3 - Using Netlify</title>
      <dc:creator>Athul Anil Kumar</dc:creator>
      <pubDate>Mon, 11 May 2020 11:05:46 +0000</pubDate>
      <link>https://forem.com/athul7744/part-3-using-netlify-4d2f</link>
      <guid>https://forem.com/athul7744/part-3-using-netlify-4d2f</guid>
      <description>&lt;p&gt;If you have followed along with the last two posts, you should've successfully created your site, deployed it and accessed it through your browser. All of the heavy lifting like creating the repo and generating the static content was done by StackBit. And finally the site was deployed by Netlify. Now let's see what Netlify does.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Netlify?
&lt;/h2&gt;

&lt;p&gt;Netlify is an all in one modern tool for automating web projects. It allows you to build and deploy your code. It prebuilds all static content and stores it in their &lt;a href="https://en.wikipedia.org/wiki/Edge_computing"&gt;edge&lt;/a&gt; servers. This allows for near instantaneous loading of content. Since our website is mainly composed of static pages, Netlify is the perfect match for deploying it. &lt;/p&gt;

&lt;p&gt;Netlify allows Continuous Integration &lt;a href="https://www.infoworld.com/article/3271126/what-is-cicd-continuous-integration-and-continuous-delivery-explained.html"&gt;(CI/CD)&lt;/a&gt; on our web projects. What this means is that as soon as you make a change in your website repository on GitHub or publish a new post on DEV, it will automatically be built, rendered and deployed to the Netlify servers. All of this is done by maintaining Netlify hooks to GitHub and DEV. As soon as a git push is done on the master branch of your website repository, Netlify receives a trigger to rebuild the website. Similarly when you post on DEV, Netlify rebuilds the website with your new post. These re-built files are then deployed to the edge servers. This automation allows a seamless method to keep your website up to date and mint.&lt;/p&gt;

&lt;h2&gt;
  
  
  Netlify : Basics/Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Change the URL of your website&lt;/strong&gt; : If you have a paid domain name you can use it, else you can have something like &lt;em&gt;&amp;lt;website-name&amp;gt;&lt;/em&gt;.netlify.app. You can change it by 

&lt;ul&gt;
&lt;li&gt;Going to &lt;a href="https://app.netlify.com/"&gt;Netlify Dashboard&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Clicking on your site name&lt;/li&gt;
&lt;li&gt;Select &lt;em&gt;Settings&lt;/em&gt; on top tab&lt;/li&gt;
&lt;li&gt;Click on &lt;em&gt;Domain Management&lt;/em&gt; on the left tab (Now you'll see your site's name) &lt;/li&gt;
&lt;li&gt;Click on &lt;em&gt;Options&lt;/em&gt; next to the name and click &lt;em&gt;Edit Name&lt;/em&gt;. Now give your preferred name and it is updated instantaneously.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Status Badge&lt;/strong&gt; : Under &lt;em&gt;General&lt;/em&gt; tab in left hand you can find how to add a deploy status badge. All you need to do is paste the code where you need to display the status (preferably on the README.md file in your GitHub repo.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Snippet injection&lt;/strong&gt; : When your static files are deployed, Netlify allows you to inject code into it. Try going to your website when you are logged in to StackBit, you'll see the StackBit control center on the top right corner. That code is injected by Netlify. For example you can also inject a Google Analytics tracker to see the analytics of your site. You can find it under &lt;em&gt;Post-Processing&lt;/em&gt; below &lt;em&gt;Build and Deploy&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Form Submissions&lt;/strong&gt; : Your website will have a contact form for people wishing to contact you. You can find the list of active forms in the &lt;em&gt;Forms&lt;/em&gt; tab in the top tab row.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Auto-Preview PR&lt;/strong&gt; : When you create a Pull Request in GitHub on your site repository, Netlify auto-generates a new link to preview the changes in your PR branch right inside GitHub. You can find more details &lt;a href="https://www.netlify.com/blog/2016/07/20/introducing-deploy-previews-in-netlify/"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hide Logs&lt;/strong&gt; : You can hide the logs of your deployment by going to &lt;em&gt;Continuous Deployment&lt;/em&gt; under &lt;em&gt;Build and Deploy&lt;/em&gt; and editing the settings. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope these points helped you understand more about how your site is being deployed. In the next post I'll focus on what Jekyll is and how to modify your website using it. Thank You for reading through.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Part 2 : The Magic - DEV to JAMStack</title>
      <dc:creator>Athul Anil Kumar</dc:creator>
      <pubDate>Sun, 10 May 2020 18:51:14 +0000</pubDate>
      <link>https://forem.com/athul7744/part-2-the-magic-dev-to-jamstack-5ci3</link>
      <guid>https://forem.com/athul7744/part-2-the-magic-dev-to-jamstack-5ci3</guid>
      <description>&lt;p&gt;Now that we have learnt what a JAMStack site is, we shall proceed to the creation  of your own blog. &lt;/p&gt;

&lt;h2&gt;
  
  
  How to start?
&lt;/h2&gt;

&lt;p&gt;Go to the &lt;em&gt;DEV Settings&lt;/em&gt; by clicking on your profile picture at the top-right corner of your window and select &lt;em&gt;Settings&lt;/em&gt;. Next navigate to &lt;em&gt;Integrations&lt;/em&gt;. Here you'll see &lt;em&gt;Generate a personal blog from your DEV posts&lt;/em&gt;. Click it and voila, you are ready. Just kidding, magic requires more work. &lt;/p&gt;

&lt;p&gt;The integration for converting your DEV posts to a self-hosted static site is done by StackBit. As you might have seen, posts on DEV are stored as Markdown files which use the Markdown syntax language. Even this post was written in Markdown syntax. StackBit takes these files (which are static of-course!) and uses them to build a blog website for you. &lt;/p&gt;

&lt;p&gt;StackBit creates a JAMStack site for you using three main components.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Static Site Generator : As the name suggests this component generates the static files for your site. Some options you'll see are &lt;em&gt;Jekyll&lt;/em&gt;, &lt;em&gt;Hugo&lt;/em&gt; and &lt;em&gt;Gatsby&lt;/em&gt;. I personally prefer &lt;em&gt;Jekyll&lt;/em&gt; for it's ease of use and for the rest of this series I'll be explaining using &lt;em&gt;Jekyll&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Repository : This is where your site data will be stored(only meta-data, not posts) and deployed from. &lt;em&gt;GitHub&lt;/em&gt; is where you'll be asked to create a repository.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/Content_management_system"&gt;CMS&lt;/a&gt; and Deployment : A content management service takes care of the storing the website and your dev posts. For deployment Stackbit gives us the option of using &lt;em&gt;Netlify&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let's create the site. The steps for this were already published by &lt;a href="https://dev.to/devteam"&gt;The DEV team&lt;/a&gt;, so I'm not going to write them here. You can find the exact instructions &lt;a href="https://dev.to/connecting-with-stackbit"&gt;here&lt;/a&gt;. If you want to find more technical details about the integration refer &lt;a href="https://dev.to/devteam/you-can-now-generate-self-hostable-static-blogs-right-from-your-dev-content-via-stackbit-7a5"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL:DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create website &lt;a href="https://app.stackbit.com/create?ref=devto"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Select a theme for your website (Fjord is awesome!)&lt;/li&gt;
&lt;li&gt;Select Jekyll Static Site generator&lt;/li&gt;
&lt;li&gt;Connect DEV and GitHub accounts (Give a funky name to your repo)&lt;/li&gt;
&lt;li&gt;Create project and connect to Netlify&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And now the magic is complete! Your site is ready. &lt;/p&gt;

&lt;p&gt;In the next post I'll explain about Netlify and some of its perks.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Part 1 : What is JAMStack?</title>
      <dc:creator>Athul Anil Kumar</dc:creator>
      <pubDate>Sun, 10 May 2020 18:01:01 +0000</pubDate>
      <link>https://forem.com/athul7744/part-1-what-is-jamstack-276j</link>
      <guid>https://forem.com/athul7744/part-1-what-is-jamstack-276j</guid>
      <description>&lt;p&gt;If you are a developer who loves writing, this post is for you. You might have already authored more than a dozen posts on DEV or you might be planning to write something (like me!). But what if you can also create a blog site of your own out of these posts. If you want to find out how, hang on tight.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Elephant
&lt;/h2&gt;

&lt;p&gt;First of all let us address the elephant in the room. JAMStack basically stands for &lt;em&gt;Javascript&lt;/em&gt;, &lt;em&gt;APIs&lt;/em&gt; and &lt;em&gt;Markdown&lt;/em&gt;. But the JAM Stack is not about specific technologies. It’s a new way of building websites and apps. You may have already seen or worked on a JAM Stack site! They do not have to include all attributes of JavaScript, APIs, and Markup. They might be built using sites built by hand, or with Jekyll, Hugo, Nuxt, Next, Gatsby, or another static site generator. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The thing that they all have in common is that they don’t depend on a web server.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;On a conventional website when you request a page, the request is sent from the client (your browser) to the server hosting the website. Here the server parses your request and fetches the data from the database. Then the data is processed and sent to your client. The client then renders the data into a form you can view.&lt;/p&gt;

&lt;p&gt;On a JAMStack website the data to be served to the user is compiled at deploy time. Ergo, when a request is received by the web server, it simply sends the pre-compiled data that can be readily rendered. We save time, the performance increases because lesser resources are required, the security is increased because the surface area for attacks are reduced and it is easier to scale since only the number of static files increase (CDNs are perfect for this use case).&lt;/p&gt;

&lt;p&gt;In conclusion, JAMStack websites work by storing the data in static files that can be readily served without further processing. For a website serving blog posts this is more than ideal, because once a post is published it is rarely edited again, it remains static. And that's why we are here.&lt;/p&gt;

&lt;p&gt;In the next post you can find out how to create a JAMStack website using your own posts on DEV.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>When using multiple JS classes which is a better way of writing code? </title>
      <dc:creator>Athul Anil Kumar</dc:creator>
      <pubDate>Wed, 29 Apr 2020 08:02:26 +0000</pubDate>
      <link>https://forem.com/athul7744/when-using-multiple-js-classes-which-is-a-better-way-of-writing-code-4001</link>
      <guid>https://forem.com/athul7744/when-using-multiple-js-classes-which-is-a-better-way-of-writing-code-4001</guid>
      <description>&lt;p&gt;I have multiple JS classes in my project, and some of them are dependant on the others. Is it better to export from a module and use it as import in another module (or) create an instance of the class I need and use it as required(here I have an HTML file where I've included all the scripts I need)?&lt;/p&gt;

&lt;p&gt;Am I missing any fundamental of export/import? Please feel free to correct.&lt;/p&gt;

&lt;p&gt;PS: I'm using Node.js&lt;/p&gt;

&lt;p&gt;Thank You&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>javascript</category>
      <category>node</category>
    </item>
  </channel>
</rss>
