HTML (index.html)
htmlCopy code<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Notes App</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Notes App</h1>
<textarea id="noteInput" placeholder="Type your note here..."></textarea>
<button id="addNoteBtn">Add Note</button>
<div id="notesList"></div>
</div>
<script src="script.js"></script>
</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', () => {
notesList.removeChild(noteDiv);
});
noteDiv.appendChild(noteContent);
noteDiv.appendChild(deleteBtn);
notesList.appendChild(noteDiv);
noteInput.value = '';
} else {
alert('Please enter a note!');
}
}
How to Run
- Create a folder on your computer and create three files inside it:
index.html
, styles.css
, and script.js
.
- Copy the respective code into each file.
- Open
index.html
in your web browser.
Leave a Reply