<?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: Mohammad Mirfatemi</title>
    <description>The latest articles on DEV Community by Mohammad Mirfatemi (@kiumad).</description>
    <link>https://dev.to/kiumad</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%2F722348%2F60dba297-5348-4998-9c81-1641b4e7708d.jpg</url>
      <title>DEV Community: Mohammad Mirfatemi</title>
      <link>https://dev.to/kiumad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kiumad"/>
    <language>en</language>
    <item>
      <title>Make Keyboard ShortCut in Javascript</title>
      <dc:creator>Mohammad Mirfatemi</dc:creator>
      <pubDate>Tue, 05 Jul 2022 13:35:05 +0000</pubDate>
      <link>https://dev.to/kiumad/make-keyboard-shortcut-in-javascript-46oc</link>
      <guid>https://dev.to/kiumad/make-keyboard-shortcut-in-javascript-46oc</guid>
      <description>&lt;p&gt;Creating a shortcut in javascript with 5 lines of code!&lt;br&gt;
To create a shortcut, we must first listen to the pressing of the keyboard keys on the document&lt;br&gt;
Then specify the keys we want to simplify with an if&lt;br&gt;
Finally, we have to eliminate the normal behavior of that shirt with preventDefault&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Listen to keydown event on the document
document.addEventListener("keydown", (e) =&amp;gt; {
  if (e.key.toLowerCase() === "s" &amp;amp;&amp;amp; e.ctrlKey) {
    // disable the default behavior of the ctrl + s
    e.preventDefault();
    // your code here
    alert("S key pressed with ctrl");
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>can you "AppendChild" same element multiple times in js ? Probably not</title>
      <dc:creator>Mohammad Mirfatemi</dc:creator>
      <pubDate>Sun, 03 Jul 2022 07:47:59 +0000</pubDate>
      <link>https://dev.to/kiumad/can-you-appendchild-same-element-multiple-times-in-js-probably-not-4j</link>
      <guid>https://dev.to/kiumad/can-you-appendchild-same-element-multiple-times-in-js-probably-not-4j</guid>
      <description>&lt;p&gt;in this case :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var d1 = document.createElement('div');
var d2 = document.createElement('div');
var p = document.createElement('p');

d1.appendChild(p); // d1 has p now
d2.appendChild(p); // d2 has p now
// but where is p in d1 ?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we cannot append "p" multiple times because in the DOM, being a tree of nodes, one node can have only one parent, it cannot have multiple parents.&lt;/p&gt;

&lt;h2&gt;
  
  
  But solution !
&lt;/h2&gt;

&lt;p&gt;We can use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode"&gt;cloneNode()&lt;/a&gt; , but I use another way &lt;br&gt;
I want to use a function&lt;br&gt;
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;//main function
function appendChildMultiple(parent) {
  //check function argument is an element
  if (parent.nodeType !== undefined) {
    const pTag = document.createElement("p");
    pTag.innerText = "This is the appended element";
    //finally append child to parent
    parent.appendChild(pTag);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and use it :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const d1 = document.createElement("div");
const d2 = document.createElement("div");
appendChildMultiple(d1);
appendChildMultiple(d2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;an example on Codepen :&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/kiumad/embed/eYMNKYa?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Do you think this method has good performance? Leave a comment below :)&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>a classic watch , width HTML CSS JS</title>
      <dc:creator>Mohammad Mirfatemi</dc:creator>
      <pubDate>Sat, 02 Jul 2022 06:32:03 +0000</pubDate>
      <link>https://dev.to/kiumad/a-classic-watch-width-html-css-js-36p</link>
      <guid>https://dev.to/kiumad/a-classic-watch-width-html-css-js-36p</guid>
      <description>&lt;p&gt;This is a simple project with HTML, CSS and Js
GitHub repository: &lt;a href="https://github.com/kiumad/clock_m"&gt;https://github.com/kiumad/clock_m&lt;/a&gt;&lt;/p&gt;

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

</description>
      <category>codepen</category>
      <category>html</category>
      <category>css</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
