My Blog

My WordPress Blog

My Blog

My WordPress Blog

Notes App

HTML (index.html)

htmlCopy code<!DOCTYPE html>
<html lang="en">
<head>
&lt;meta charset="UTF-8"&gt;
&lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
&lt;title&gt;Simple Notes App&lt;/title&gt;
&lt;link rel="stylesheet" href="styles.css"&gt;
</head> <body>
&lt;div class="container"&gt;
    &lt;h1&gt;Notes App&lt;/h1&gt;
    &lt;textarea id="noteInput" placeholder="Type your note here..."&gt;&lt;/textarea&gt;
    &lt;button id="addNoteBtn"&gt;Add Note&lt;/button&gt;
    &lt;div id="notesList"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src="script.js"&gt;&lt;/script&gt;
</body> </html>

CSS (styles.css)

cssCopy codebody {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
} .container {
max-width: 600px;
margin: auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
} h1 {
text-align: center;
} textarea {
width: 100%;
height: 100px;
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
resize: none;
} button {
width: 100%;
padding: 10px;
background-color: #28a745;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
} button:hover {
background-color: #218838;
} .note {
background-color: #e9ecef;
padding: 10px;
margin: 10px 0;
border-radius: 4px;
position: relative;
} .deleteBtn {
position: absolute;
top: 10px;
right: 10px;
background: red;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}

JavaScript (script.js)

javascriptCopy codedocument.getElementById('addNoteBtn').addEventListener('click', addNote);

function addNote() {
const noteInput = document.getElementById('noteInput');
const noteText = noteInput.value.trim();
if (noteText) {
    const notesList = document.getElementById('notesList');
    const noteDiv = document.createElement('div');
    noteDiv.classList.add('note');
    const noteContent = document.createElement('p');
    noteContent.textContent = noteText;
    const deleteBtn = document.createElement('button');
    deleteBtn.textContent = 'Delete';
    deleteBtn.classList.add('deleteBtn');
    deleteBtn.addEventListener('click', () =&gt; {
        notesList.removeChild(noteDiv);
    });
    noteDiv.appendChild(noteContent);
    noteDiv.appendChild(deleteBtn);
    notesList.appendChild(noteDiv);
    noteInput.value = '';
} else {
    alert('Please enter a note!');
}
}

How to Run

  1. Create a folder on your computer and create three files inside it: index.html, styles.css, and script.js.
  2. Copy the respective code into each file.
  3. Open index.html in your web browser.
Notes App

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top