<?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: Gloria Ojukwu (tech_bella)</title>
    <description>The latest articles on DEV Community by Gloria Ojukwu (tech_bella) (@gloriaojuks).</description>
    <link>https://dev.to/gloriaojuks</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%2F213254%2F1c3566d3-1d24-4aa8-bdc0-d8bf86c1d5a4.jpg</url>
      <title>DEV Community: Gloria Ojukwu (tech_bella)</title>
      <link>https://dev.to/gloriaojuks</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gloriaojuks"/>
    <language>en</language>
    <item>
      <title>THE DOM, THE DOM, THE DOM, What exactly is that?(part 2)</title>
      <dc:creator>Gloria Ojukwu (tech_bella)</dc:creator>
      <pubDate>Tue, 24 Dec 2019 13:25:41 +0000</pubDate>
      <link>https://dev.to/gloriaojuks/the-dom-the-dom-the-dom-what-exactly-is-that-part-2-1nho</link>
      <guid>https://dev.to/gloriaojuks/the-dom-the-dom-the-dom-what-exactly-is-that-part-2-1nho</guid>
      <description>&lt;p&gt;&lt;strong&gt;DOM Manipulation with Javascript.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In part 1 of this article . &lt;a href="https://dev.to/gloriaojuks/the-dom-the-dom-the-dom-what-exactly-is-that-ank"&gt;https://dev.to/gloriaojuks/the-dom-the-dom-the-dom-what-exactly-is-that-ank&lt;/a&gt; , we looked at the basics of DOM and what the DOM really is. We also saw that we could use javascript to manipulate the DOM but didn't dive dip into that. In this article, we'll look at how we can manipulate the DOM with javascript. &lt;/p&gt;

&lt;p&gt;In the last article, we established the foundation that the DOM is an API to web pages and that's why programs like javascript can manipulate and change it.&lt;/p&gt;

&lt;p&gt;To understand this easier, the concept of DOM Manipulation can be broken down into CRUD. CRUD basically stands for Create, Read, Update and Delete, but in the case of the DOM, we'll be performing these actions on the DOM Node so we have&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reading  the DOM Nodes&lt;/li&gt;
&lt;li&gt;Creating the DOM Nodes&lt;/li&gt;
&lt;li&gt;Updating the DOM Nodes&lt;/li&gt;
&lt;li&gt;Deleting the DOM Nodes&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Reading the DOM nodes&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
There are many ways to read the DOM nodes but I will explain some of the most used ones. Some of the most used/important ones are:&lt;br&gt;
• querySelector&lt;/p&gt;

&lt;p&gt;The querySelector() method returns the first element that matches a specified CSS selector(s) in the document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Syntax: document.querySelector(‘&amp;lt;CSS Selector&amp;gt;’);

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





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;h2 class="example"&amp;gt;A heading with class="example"&amp;lt;/h2&amp;gt;
&amp;lt;p class="example"&amp;gt;A paragraph with class="example".&amp;lt;/p&amp;gt; 

&amp;lt;p&amp;gt;Click the button to add a background color to the first element in the document with class="example".&amp;lt;/p&amp;gt;

&amp;lt;button onclick="myFunction()"&amp;gt;Try it&amp;lt;/button&amp;gt;

&amp;lt;script&amp;gt;
function myFunction() {
  document.querySelector(".example").style.backgroundColor = "blue";
}
&amp;lt;/script&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the example above, the element with the css selector inside the .queryselector() method is targeted, in this case, ".example". So in this example, the first element with the ".example" class name is targeted and the background is changed to blue when the code runs&lt;/p&gt;

&lt;p&gt;Note that the querySelector() method only returns the first element that matches the specified selectors. To return all the matches, use the querySelectorAll() method instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Syntax: document.querySelectorAll(‘&amp;lt;CSS Selector&amp;gt;’);

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





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;h2 class="example"&amp;gt;A heading with class="example"&amp;lt;/h2&amp;gt;
&amp;lt;p class="example"&amp;gt;A paragraph with class="example".&amp;lt;/p&amp;gt; 
&amp;lt;h3 class="example"&amp;gt;this is a heading&amp;lt;/h3&amp;gt;

&amp;lt;p&amp;gt;Click the button to add a background color all elements with class="example".&amp;lt;/p&amp;gt;

&amp;lt;button onclick="myFunction()"&amp;gt;Try it&amp;lt;/button&amp;gt;

&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;Note:&amp;lt;/strong&amp;gt; The querySelectorAll() method is not supported in Internet Explorer 8 and earlier versions.&amp;lt;/p&amp;gt;

&amp;lt;script&amp;gt;
function myFunction() {
  var x, i;
  x = document.querySelectorAll(".example");
  for (i = 0; i &amp;lt; x.length; i++) {
    x[i].style.backgroundColor = "red";
  }
}
&amp;lt;/script&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So run the code and notice that with the querySelectorAll() method, all the elements with the CSS selector in question are targeted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Creating the DOM Nodes&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
To create DOM Nodes, the createElement() is used. See example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;p&amp;gt;Click the button to make a BUTTON element with text.&amp;lt;/p&amp;gt;

&amp;lt;button onclick="myFunction()"&amp;gt;Try it&amp;lt;/button&amp;gt;

&amp;lt;script&amp;gt;
 function myFunction() {
  let button = document.createElement("BUTTON");
  button.innerText = "CLICK us";
  document.body.appendChild(button);
}
&amp;lt;/script&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

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



&lt;p&gt;Notice that to create a text, we used innerText or innerHTML property instead. Finally we added the button created to the DOM by using the appendChild() method with the element created as the parameter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Updating the DOM Nodes&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;syntax: document.getElementById(id).innerHTML = new HTML
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Using the innerHTML property is the easiest way to modify the content of an HTML element &lt;/p&gt;

&lt;p&gt;See the example below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;h2&amp;gt;JavaScript can Change HTML&amp;lt;/h2&amp;gt;

&amp;lt;h1 id="heading"&amp;gt;Sup Guys&amp;lt;/h1&amp;gt;

&amp;lt;script&amp;gt;
document.getElementById("h1").innerHTML = "I am the updated text!";
&amp;lt;/script&amp;gt;

&amp;lt;h1&amp;gt;The paragraph above was changed by a script.&amp;lt;/h1&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;using the getElementById() method and the innerHTML property, the text in the DOM was updated to a new text. Try out the code in your editor and see the changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Deleting the DOM Nodes&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Removing a DOM node is pretty straight forward, we simply access the parent node first, then from there, we delete the child.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Syntax: elementNode.parentNode.removeChild(elementNode);

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



&lt;p&gt;See the example below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Manipualting the DOM&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;p id="paraId"&amp;gt;A paragrapgh&amp;lt;/p&amp;gt;
  &amp;lt;/body&amp;gt;
  &amp;lt;script&amp;gt;
    //accessing the node with id="paraId"
    let firstPara = document.querySelector('#paraId'); 

    //deleting the element node
    firstPara.parentNode.removeChild(firstPara);
  &amp;lt;/script&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So you need to have the HTML code existing, then you introduce the script to see the content disappear.&lt;/p&gt;

&lt;p&gt;Thanks for reading my article. For any concerns or questions, send me a DM @tech_bella on Twitter or leave comments below.&lt;/p&gt;

&lt;p&gt;E go be! (Nigerian Pidgin version of saying bye) &lt;/p&gt;

</description>
    </item>
    <item>
      <title>THE DOM, THE DOM, THE DOM, What exactly is that?</title>
      <dc:creator>Gloria Ojukwu (tech_bella)</dc:creator>
      <pubDate>Mon, 09 Dec 2019 08:35:47 +0000</pubDate>
      <link>https://dev.to/gloriaojuks/the-dom-the-dom-the-dom-what-exactly-is-that-ank</link>
      <guid>https://dev.to/gloriaojuks/the-dom-the-dom-the-dom-what-exactly-is-that-ank</guid>
      <description>&lt;p&gt;I wrote HTML, CSS and Javascript codes up to 3 years ago without understanding the exact meaning of the DOM, in fact, I used to think my HTML  code was the DOM, even though I made constant use of it. Weird right? &lt;/p&gt;

&lt;p&gt;SO WHAT EXACTLY IS THE DOM?&lt;/p&gt;

&lt;p&gt;The DOM stands for the Document Object Model.&lt;/p&gt;

&lt;p&gt;The MDN Web Docs defines the DOM as "a programming interface for HTML and XML documents. It represents the page so that programs can change the document structure, style, and content. The DOM represents the document as nodes and objects. That way, programming languages can connect to the page."&lt;/p&gt;

&lt;p&gt;Simply put, the DOM is an API to web pages. This is why programs like javascript can manipulate and change it. &lt;/p&gt;

&lt;p&gt;You must have also heard some people refer to the DOM as a Tree. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EUGlr_vF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.tutorialrepublic.com/lib/images/html-dom-illustration.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EUGlr_vF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.tutorialrepublic.com/lib/images/html-dom-illustration.png" alt="dom tree"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the image above, you can see the tree-like structure, people refer to it as a tree because the DOM starts with a single parent item that branches into children items and even more children items.&lt;/p&gt;

&lt;p&gt;Note that the DOM is not;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;the same as your HTML source code even though it is created from &lt;br&gt;
there: this can be verified from an instance when you mistakenly leave &lt;br&gt;
out a required element. You'll notice it in the DOM even though &lt;br&gt;
you've left it out of your HTML. also after modifying the DOM with &lt;br&gt;
Javascript, you'd also notice that the DOM is different from your HTML &lt;br&gt;
source code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the same as what you see in the Dev tools: If you're familiar with the &lt;br&gt;
dev tools, you'd notice that it adds additional information that is &lt;br&gt;
not in the Dom such as Pseudo-elements created using the ::before and &lt;br&gt;
::after selectors, but these are not in the DOM.    &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In part 2 of this article, I will discuss how you modify the DOM with Javascript.&lt;/p&gt;

&lt;p&gt;Summary:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The DOM is an API for HTML and XML documents. It represents the page so &lt;br&gt;
that programs can change the document structure, style, and content. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The DOM is not the same as your HTM source code even though it is &lt;br&gt;
generated from it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The DOM is not the same as what you see in the Dev tools because the &lt;br&gt;
dev tools contains extra information like the pseudo-elements (::before &lt;br&gt;
and ::before)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Super thanks for reading my article about the DOM. Kindly follow me on twitter @tech_bella for interesting Tech tweets. You can ask questions or make comments in the comment section below. &lt;/p&gt;

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