<?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: Josephine Luu</title>
    <description>The latest articles on DEV Community by Josephine Luu (@josephineluu).</description>
    <link>https://dev.to/josephineluu</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%2F889563%2Fc9f5ac00-1e42-4c10-a961-bbc635a42d82.png</url>
      <title>DEV Community: Josephine Luu</title>
      <link>https://dev.to/josephineluu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/josephineluu"/>
    <language>en</language>
    <item>
      <title>Rails: Active Record Validation Helpers</title>
      <dc:creator>Josephine Luu</dc:creator>
      <pubDate>Sat, 10 Sep 2022 02:03:51 +0000</pubDate>
      <link>https://dev.to/josephineluu/rails-active-record-validation-helpers-bmh</link>
      <guid>https://dev.to/josephineluu/rails-active-record-validation-helpers-bmh</guid>
      <description>&lt;h2&gt;
  
  
  Why do we use validations?
&lt;/h2&gt;

&lt;p&gt;Validations are used to ensure that data you want is saved correctly into your database. For example, you wouldn't want someone to put a phone number in a email form. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xp7sPhGU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmyl5ahqdn6lu6sctary.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xp7sPhGU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmyl5ahqdn6lu6sctary.jpeg" alt="Image description" width="599" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Validation Helpers
&lt;/h2&gt;

&lt;p&gt;I'll be going over some validation helpers along with some examples provided. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. presence&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GYK8zS_F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aor7tjg64ftv1ggnmbda.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GYK8zS_F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aor7tjg64ftv1ggnmbda.png" alt="Image description" width="632" height="112"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In line 3, this is how you would use presence. This is saying &lt;br&gt;
that a name &lt;strong&gt;has&lt;/strong&gt; to be there. If a user were to try and &lt;br&gt;
create a mission without a name, it wouldn't work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. uniqueness&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oADGpMhw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38j40gbv3vo3xr6husxv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oADGpMhw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38j40gbv3vo3xr6husxv.png" alt="Image description" width="676" height="122"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is saying that a email &lt;strong&gt;has&lt;/strong&gt; to be unique.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. length&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PdwLrWCO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8uxs0sty2fr49wq2d7bf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PdwLrWCO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8uxs0sty2fr49wq2d7bf.png" alt="Image description" width="846" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With each of these, it can have a minimum, maximum, in, and is. Minimum and maximum is pretty self explanatory. For in, it's saying that the password has to be a length within 6 to 20 characters. As for is, it has to be 6 characters exactly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. inclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FJrvIjCt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cjfaelc6664mvbzujh33.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FJrvIjCt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cjfaelc6664mvbzujh33.png" alt="Image description" width="880" height="134"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In line 2, this is saying that strength can only be strong, weak, or average. In rails console, if you enter %w(Strong Weak Average), it will give you an array.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ef9omq2x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c4d1afnj8yz9f2bjs1wb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ef9omq2x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c4d1afnj8yz9f2bjs1wb.png" alt="Image description" width="534" height="56"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In line 3, it's saying the age has to be between 8 and 18.&lt;/p&gt;

&lt;p&gt;These are just a few active record validations, but if you are interested in looking at more, I would visit &lt;a href="https://guides.rubyonrails.org/active_record_validations.html"&gt;here&lt;/a&gt;. Thanks for reading and good luck coding!&lt;/p&gt;

&lt;p&gt;sources: &lt;a href="https://guides.rubyonrails.org/active_record_validations.html"&gt;https://guides.rubyonrails.org/active_record_validations.html&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Active Record Associations</title>
      <dc:creator>Josephine Luu</dc:creator>
      <pubDate>Sun, 21 Aug 2022 18:41:00 +0000</pubDate>
      <link>https://dev.to/josephineluu/active-record-associations-16kd</link>
      <guid>https://dev.to/josephineluu/active-record-associations-16kd</guid>
      <description>&lt;p&gt;&lt;strong&gt;What are Active Record Associations?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Association is the relationship between models and it's used to make it easier on coders like you. Let's dive into the different types of associations with a example for each.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 6 Types of Associations
&lt;/h2&gt;

&lt;p&gt;1.&lt;strong&gt;belongs_to&lt;/strong&gt;&lt;br&gt;
A belongs_to association creates a connection with another model. The associations has to be used in a singular term because Rails will automatically infer the class name from the association name. In this example, each review can be assigned to exactly one user. It will look for a user_id on the reviews table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--61wJBbbA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cga94aksdinfoj26razh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--61wJBbbA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cga94aksdinfoj26razh.png" alt="Image description" width="492" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;has_one&lt;/strong&gt;&lt;br&gt;
A has_one association indicates that one other model has a reference to this model. For example, each supplier only has one account. The account will be associate with supplier_id.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CFwjar2B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwamchsrz0w4mzcfskql.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CFwjar2B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwamchsrz0w4mzcfskql.png" alt="Image description" width="520" height="104"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.&lt;strong&gt;has_many&lt;/strong&gt;&lt;br&gt;
A has_many association is a one-to-many connection with another model. The associations has to be used in a plural term. For example, a user can have many reviews in this example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GSb7hwce--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h5mks79tk57grkvy1pqd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GSb7hwce--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h5mks79tk57grkvy1pqd.png" alt="Image description" width="500" height="106"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hUOkNlHT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/63e0drns1msspa31yrvb.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hUOkNlHT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/63e0drns1msspa31yrvb.jpeg" alt="Image description" width="800" height="576"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4.&lt;strong&gt;has_many :through&lt;/strong&gt;&lt;br&gt;
A has_many :through association has a many-to-many connection with another model. The models are connected &lt;em&gt;through&lt;/em&gt; another model. For example, a game &lt;strong&gt;has many&lt;/strong&gt; users, &lt;strong&gt;through&lt;/strong&gt; reviews and a user &lt;strong&gt;has many&lt;/strong&gt; games, &lt;strong&gt;through&lt;/strong&gt; reviews. A review &lt;strong&gt;belongs to&lt;/strong&gt; a game and a user. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l9xYue41--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/51sko6bt4gof4ndfa8et.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l9xYue41--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/51sko6bt4gof4ndfa8et.png" alt="Image description" width="558" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The tables will look something like this.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kX0iY2dn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o99ds25ps79lo7y6omz3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kX0iY2dn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o99ds25ps79lo7y6omz3.png" alt="Image description" width="830" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5.&lt;strong&gt;has_one :through&lt;/strong&gt;&lt;br&gt;
A has_one :through association sets a one-to-one connection with another model but can proceed through a third model. For example, if a department &lt;strong&gt;has one&lt;/strong&gt; manager, and each manager is associated with one manager history, then it will look like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D8I9Qiuu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/57hcla8t8x7648lk65e8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D8I9Qiuu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/57hcla8t8x7648lk65e8.png" alt="Image description" width="680" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6.&lt;strong&gt;has_and_belongs_to_many&lt;/strong&gt;&lt;br&gt;
A has_and_belongs_to_many association is similar to the has_many :through association, but there is no third model. For example, there was a review model, but now there is only a game and user model.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UOkQ6eCb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1wj04rk3zhm1k06xtmk2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UOkQ6eCb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1wj04rk3zhm1k06xtmk2.png" alt="Image description" width="578" height="838"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is also a polymorphic association that is more advanced and to learn more about that I would recommend visiting &lt;a href="https://guides.rubyonrails.org/association_basics.html"&gt;this&lt;/a&gt;. I hope this was helpful and good luck coding!&lt;/p&gt;

&lt;p&gt;Sources:&lt;br&gt;
-&lt;a href="https://guides.rubyonrails.org/association_basics.html"&gt;https://guides.rubyonrails.org/association_basics.html&lt;/a&gt;&lt;br&gt;
-&lt;a href="https://www.youtube.com/watch?v=5mhuNSkV_vQ&amp;amp;t=409s"&gt;https://www.youtube.com/watch?v=5mhuNSkV_vQ&amp;amp;t=409s&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React Functional Components</title>
      <dc:creator>Josephine Luu</dc:creator>
      <pubDate>Sat, 30 Jul 2022 19:13:00 +0000</pubDate>
      <link>https://dev.to/josephineluu/react-functional-components-46m4</link>
      <guid>https://dev.to/josephineluu/react-functional-components-46m4</guid>
      <description>&lt;p&gt;As you start out learning React, you may have came across React components and became confused. I hope by reading this, you can gain more clarity. As such, I will break down what a React component is, why it's used, and how it's used with a few examples. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a React component?&lt;/strong&gt;&lt;br&gt;
It's simply building blocks being used to break down and simplify how a website works. For example, in the image below, you can see how the Google page is broken down into several parts like Logo, WordBox, SearchButton, etc. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bo3FekAF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t8ttnt69qgupv1f3imao.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bo3FekAF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t8ttnt69qgupv1f3imao.png" alt="Image description" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why would anyone want to do that?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By breaking down a website with components, it makes it easier for the coder to identify and update any mistakes made. One of the main benefits in using components, is being able to save time by reusing components. These are just a few reasons to use components, but if you want learn about more then I would suggest clicking &lt;a href="https://www.uxpin.com/studio/blog/reactjs-benefits-and-components/"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Functional Components&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Functional components are javascript functions that must start with a capital letter. They usually pass in properties, also known as props. To learn more about props, I would suggest clicking &lt;a href="https://www.w3schools.com/react/react_props.asp"&gt;here&lt;/a&gt;. A example of how a functional component looks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function WordBox(){
  return &amp;lt;div&amp;gt;Hi!&amp;lt;/div&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another way functional components are written are like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const WordBox = () =&amp;gt; &amp;lt;div&amp;gt;Hi!&amp;lt;/div&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is always some top level component and most often it is a component called App. With any component, it can call other components as well. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App(){
  return (
     &amp;lt;div&amp;gt;
      &amp;lt;WordBox/&amp;gt;
      &amp;lt;Logo/&amp;gt;
     &amp;lt;/div&amp;gt;
   );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see that it's calling the component WordBox we used in the example above and Logo as a component in the picture shown above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rendering Components&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In order for the components to show, it needs to be rendered using ReactDOM.render() method. Most often there is a file called index.js where ReactDOM.render() is used, although the file name doesn't have to be called that. The method will pass in the &lt;strong&gt;top level component&lt;/strong&gt; as the first argument, and then pass &lt;code&gt;document.getElementById("root")&lt;/code&gt; in the second argument. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ReactDOM.render(&amp;lt;App /&amp;gt;, document.getElementById("root"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see here that the component App, the top level component, is being called. With &lt;code&gt;document.getElementById("root")&lt;/code&gt;, it is getting the element in the HTML file, that you will need to create, with the ID of root. To learn more about the HTML file, I would suggest clicking &lt;a href="https://www.w3schools.com/react/react_render.asp"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I hope this provided clarity for you and good luck coding! &lt;/p&gt;

&lt;p&gt;Sources used:&lt;/p&gt;

&lt;p&gt;-&lt;a href="https://blog.devgenius.io/java-script-lets-talk-react-basics-322629bb6e62"&gt;Picture image&lt;/a&gt;&lt;br&gt;
-&lt;a href="https://reactjs.org/docs/components-and-props.html"&gt;https://reactjs.org/docs/components-and-props.html&lt;/a&gt;&lt;br&gt;
-&lt;a href="https://www.geeksforgeeks.org/reactjs-components/"&gt;https://www.geeksforgeeks.org/reactjs-components/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Creating HTML DOM elements with Javascript</title>
      <dc:creator>Josephine Luu</dc:creator>
      <pubDate>Mon, 11 Jul 2022 22:20:03 +0000</pubDate>
      <link>https://dev.to/josephineluu/creating-html-dom-elements-with-javascript-11mm</link>
      <guid>https://dev.to/josephineluu/creating-html-dom-elements-with-javascript-11mm</guid>
      <description>&lt;p&gt;If you're reading this then you must know a little bit about what HTML and Javascript is. So how exactly do you create a HTML DOM element with Javascript? It's not an easy concept to grasp as a beginner in Javascript but hopefully after reading this, you can gain a better understanding. Let's start with the basics. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a HTML element?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A HTML element includes everything in between the first tag to the end of the tag. For example, &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;p&amp;gt;A paragraph&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Not all HTML files include tags like a paragraph tag &lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt; or an image tag &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;. Knowing how to create a HTML tag with javascript is essential if you want to add anything to the page without touching the HTML file. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do you create a HTML DOM element with Javascript?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will use this HTML code in reference to our code examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;div id='create-cat'&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;1) Create an element by using &lt;code&gt;document.createElement("x")&lt;/code&gt;. &lt;br&gt;
   X represents any element you're trying to create.&lt;br&gt;
   For example, if you want to create the element &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; &lt;br&gt;
   and declare it as a variable, you will type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; let imgTag = document.createElement("img")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Select where you want to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/append"&gt;append&lt;/a&gt; the &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tag. In this case, append it to the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag. Declare it as a variable so you can reference back to it later. To do that, you will type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let catCreation = document.querySelector("#create-cat")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Now, to actually append the &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tag under the div tag, you will type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;catCreation.append(imgTag)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will make the code on the HTML DOM look like this now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;div id='create-cat'&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;img&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4) To make an image show, you will need to include the source path to the image. So, you will type the variable name you used to create the &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tag. Enter &lt;code&gt;.src&lt;/code&gt; after and set it equal to the image file or link. See the example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;imgTag.src="img.cat_jpg"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you should see the cat image and and the HTML DOM will now look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;div id='create-cat'&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;img src="img.cat.jpg"&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Success! You have officially created a new HTML DOM element and appended it. Best of luck coding!&lt;/p&gt;

&lt;p&gt;Cover image source: &lt;a href="https://www.canto.com/blog/insert-image-html/"&gt;https://www.canto.com/blog/insert-image-html/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
