<?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: muhammadhashir153</title>
    <description>The latest articles on DEV Community by muhammadhashir153 (@muhammadhashir153).</description>
    <link>https://dev.to/muhammadhashir153</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%2F1142173%2Fe21f75a9-256d-4151-bb05-c2afa95ad89f.png</url>
      <title>DEV Community: muhammadhashir153</title>
      <link>https://dev.to/muhammadhashir153</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/muhammadhashir153"/>
    <language>en</language>
    <item>
      <title>Having issues, anyone to help?</title>
      <dc:creator>muhammadhashir153</dc:creator>
      <pubDate>Sat, 19 Aug 2023 23:25:10 +0000</pubDate>
      <link>https://dev.to/muhammadhashir153/having-issues-anyone-to-help-3dh8</link>
      <guid>https://dev.to/muhammadhashir153/having-issues-anyone-to-help-3dh8</guid>
      <description>&lt;p&gt;document.addEventListener('DOMContentLoaded', function(){&lt;br&gt;
    modalFunction();&lt;br&gt;&lt;br&gt;
    saveFunction();&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;//creating user's input to get the relevant data..&lt;br&gt;
function modalFunction(){&lt;br&gt;
    var modal = document.querySelector('.modal'),&lt;br&gt;
        btn = document.getElementById('add'),&lt;br&gt;
        closeBtn = document.getElementById('cancel'),&lt;br&gt;
        saveBtn = document.getElementById('save');&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//for opening modal..
btn.addEventListener('click', function(){
    modal.classList.add('active');
});
//for closing modal using cancel button and esc keypress..
closeBtn.addEventListener('click', function(){
    modal.classList.remove('active');
});
modal.addEventListener('keydown', function(event){
    if(event.key === 'Esc'){
        modal.classList.remove('active');
    }
});


//adding event listners to run the saveitem() function..
saveBtn.addEventListener('click', function(){
    saveItem();
});
modal.addEventListener('keydown', function(event){
    if(event.key === 'Enter'){
        event.preventDefault();
        saveItem();
    }
});

// Initializing the local storage array once
if (!localStorage.getItem('list')) {
    localStorage.setItem('list', JSON.stringify([]));
}

//defining saveitem() function here...

function saveItem(){
    var heading = document.getElementById('heading'),
        content = document.getElementById('content');

    if (heading.value !== '' &amp;amp;&amp;amp; content.value !== '') {

        //closing modal on successful submission..
        modal.classList.remove('active');

        //creating local storage...

        let data = JSON.parse(localStorage.getItem('list') || []);
        data.push({h:heading.value, p:content.value});
        localStorage.setItem('list', JSON.stringify(data));

        //refreshing values after successful submission..
        heading.value = '';
        content.value = '';

    }else{
        alert('Please fill out these fields!')
    }
}    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;//printing the user's data..&lt;br&gt;
function saveFunction(){&lt;br&gt;
    var screen = document.querySelector('main div')&lt;br&gt;
        storedItems = JSON.parse(localStorage.getItem('list'));&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var screen = document.querySelector('main div');
screen.innerHTML = '';

// Display static heading
var headingElement = document.createElement('h1');
headingElement.innerText = 'To Do List';
screen.appendChild(headingElement);

if (storedItems &amp;amp;&amp;amp; storedItems.length &amp;gt; 0) {
    storedItems.forEach(item =&amp;gt; {
        let div = document.createElement('div'),
            h = document.createElement('h3'),
            p = document.createElement('p');

        h.innerText = item.h;
        p.innerText = item.p;

        div.classList.add('screen');
        div.appendChild(h);
        div.appendChild(p);

        screen.appendChild(div);
    });
}else{
    let msg = document.createElement('p');
    msg.innerText = 'Nothing to See! click add new button on the bottom right corner of this page to create a new list!'
    screen.appendChild(msg);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

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