Skip to content
This is my space, where experience meets the will to start over. This is my space, where experience meets the will to start over.

The first step is knowing where you want to go.

  • Home
  • Coding Hub
    • Software & Project
      • Small Biz Ops – S.B.O.
        • SmallBizOps – Day 10/90
      • CRM/ERP
      • MyTracker
      • My Budget
    • Form Zero to “WoW”
      • JavaScript from Zero (Completed)
        • 2. Remove and Edit List Items
        • 3. Separate HTML and JavaScript, Use addEventListener and Conditional Logic
        • 4. Add Dynamic CSS Classes
        • 5. Save & Restore Your List with localStorage
        • 6 – Turn Your App into a Full To-Do List
      • Python from Zero (Completed)
        • 2. Lists & Loops
        • 3. Conditional Menus
        • 4. Edit & Remove Tasks (with closing: Python vs PHP and Large Data)
        • 5 – Save to File: Make Your Tasks Survive Restarts
        • 6 — Pythin from zero – Final Project Polishing: Numbering, Formatting, and Preparing for CSV
      • Rust – From Zero to “WoW” (Completed)
        • 1 – Setup and Project Structure in Rust
        • 2 – User input: validation and error handling
        • 3 – Rust from Zero to “WoW – BMI Calculation and Conditional Logic
        • 4 –Rust – Clear, Formatted Output
        • 5 – Rust – Final Thoughts: Precision as a Form of Respect
      • Go from Zero to “WoW” (Completed)
        • 1 – Why Go Is Perfect for a Personal Expense Tracker
        • 2 – Logging Expenses and Console Input
        • 3 – Go from Zero to “WoW” – Smart Filtering & Display Logic
        • 4 – Go – Saving Data to Local Files
        • 5 – Go – Final Project – Expense Tracker in Go
      • C++ from Zero to “WoW” (Completed)
        • 1 – Why C++ for file organization?
        • 2 – C++ – File Type Detection and Classification
        • 3 – C++ – Creating & Managing Subfolders
        • 4 – C++ – Safe File Movement and User Feedback
        • 5 – C++ – Order as Mental Clarity
      • Ubuntu – From Zero to “WoW” (Completed)
        • 2 – Ubuntu – The Desktop Environment and Essential Commands
        • 3 – Ubuntu – Managing Files, Folders, and Permissions
        • 4 – Ubuntu – Installing and Updating Software with APT and Snap
        • 5 – Ubuntu – Customizing the Desktop Environment
        • 6 – Ubuntu – Network and Device Configuration
        • 7 – Ubuntu – User Management & System Security — “The Cathedral of Permissions”
        • 8 – Ubuntu – The Talking Machine: Terminal & Bash Scripting
        • 9 – Ubuntu – Ubuntu as a Server or Development Environment
        • 10 – Ubuntu – Backup, Maintenance & Troubleshooting
    • Git Hub Repository
      • Small Biz Ops – S.B.O.
      • Mini ERP – PHP & MySQL
      • CleverCRM (Java, Spring Boot)
      • FraudWatch (Python, FastAPI + scikit-learn)
      • OnboardIQ – Smart Onboarding Portal (Flask + SQLite Demo)
    • ArchPilot
      • 1-Users & Roles, End-to-End (Architecture, Database, and Cross-Framework Code)
      • 2 – Client Registry (CRM) Across Frameworks
      • 3 – Project & Budget Tracker (ERP)
      • 4 – Approval Workflow Engine Multi-step routing, status tracking, escalation paths
      • 5 – Audit Trail & Versioning
    • Small Biz Ops – S.B.O.
  • Vivere in USA
  • P4Y
  • Testi poetici
    • 1 – Sospeso
    • 2 – Il bicchiere di vetro quieto
    • 3 – Quando l’amore inciampa
    • 4 – Ma chi siete davvero?
    • 5 – Above the Thread of Day
    • 6 – The Truth That Doesn’t Exist
    • 7 – All of You, I Miss
    • 8 – The Captain and the Ocean
    • 9 – Between Light and Mist
    • 10 – Il peso delle scelte
  • Contact
  • Admin
This is my space, where experience meets the will to start over.
This is my space, where experience meets the will to start over.

The first step is knowing where you want to go.

Coding – Step 9.2: JavaScript from Scratch – Remove and Edit List Items

Posted on 23 Luglio 20259 Agosto 2025 By Francesco

Welcome to Step 9.2 of our JavaScript from Scratch series.

After learning how to add items to your shopping list, today we’ll take it to the next level: you’ll be able to edit and delete each item, just like in a real interactive app.

And, as always, we’ll explain everything step by step — so you know exactly what you’re doing and why.


What is the DOM?

The DOM (Document Object Model) is a live, structured representation of your HTML page. Think of it as a tree of elements that JavaScript can interact with in real time.

Every HTML tag (<div>, <ul>, <li>, etc.) is a node in this tree.

✅ For example, when you use document.getElementById("item-input"), you’re telling the browser:
“Find the part of the page with id="item-input" and give me access to it.”

So JavaScript doesn’t change your HTML file directly — it talks to the DOM, which changes what the user sees in real time.


The Code: Add – Edit – Remove

🔹 HTML – The structure of the list

<div class="shopping-app">
  <h2>Your Shopping List 📝</h2>
  <div class="input-group">
    <input type="text" id="item-input" placeholder="Add an item..." />
    <button id="add-btn">Add</button>
  </div>
  <ul id="shopping-list"></ul>
</div>

JavaScript – The interactive logic

<script>
document.addEventListener("DOMContentLoaded", () => {
  const list = document.getElementById("shopping-list");
  const addBtn = document.getElementById("add-btn");
  const input  = document.getElementById("item-input");

  function addItem(text) {
    const li = document.createElement("li");
    const span = document.createElement("span");
    span.textContent = text;

    const editBtn = document.createElement("button");
    editBtn.textContent = "Edit";
    editBtn.className = "edit-btn";
    editBtn.addEventListener("click", () => {
      const newText = prompt("Edit item:", span.textContent);
      if (newText !== null && newText.trim() !== "") {
        span.textContent = newText.trim();
      }
    });

    const removeBtn = document.createElement("button");
    removeBtn.textContent = "Remove";
    removeBtn.className = "remove-btn";
    removeBtn.addEventListener("click", () => {
      li.remove();
    });

    li.appendChild(span);
    li.appendChild(editBtn);
    li.appendChild(removeBtn);
    list.appendChild(li);
  }

  addBtn.addEventListener("click", () => {
    const value = input.value.trim();
    if (value !== "") {
      addItem(value);
      input.value = "";
      input.focus();
    }
  });

  input.addEventListener("keyup", event => {
    if (event.key === "Enter") addBtn.click();
  });
});
</script>

CSS – To make it clean and nice

.input-group {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}
#item-input {
  flex: 1;
  padding: 8px;
}
.edit-btn, .remove-btn {
  margin-left: 8px;
  padding: 5px 10px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.edit-btn {
  background-color: #3498db;
  color: white;
}
.remove-btn {
  background-color: #e74c3c;
  color: white;
}
.edit-btn:hover {
  background-color: #2980b9;
}
.remove-btn:hover {
  background-color: #c0392b;
}

Explaining Every Line (JavaScript)

▶️ document.getElementById(...)

Grabs an element from the DOM. This connects your JS to HTML.

▶️ addEventListener("click", ...)

Attaches a reaction (function) to an event — like clicking a button.

▶️ createElement("li"), createElement("button")

Creates new HTML elements dynamically.

▶️ appendChild(...)

Inserts one element into another — like buttons inside a list item.

▶️ prompt(...)

Shows a popup to let the user enter new text (for editing).

▶️ li.remove()

Deletes the entire list item from the DOM.

▶️ textContent

Reads or sets the visible text of an element.

▶️ keyup + event.key === "Enter"

Lets the user hit Enter instead of clicking the Add button.


 Click here to test the project

📘 Command Glossary

CommandWhat it does
getElementById()Finds an element by its ID
addEventListener()Listens for events like clicks or key presses
createElement()Creates a new HTML element
appendChild()Inserts an element into another
textContentGets or sets the visible text inside an element
prompt()Opens a popup to get user input
remove()Deletes an element from the DOM
trim()Removes spaces from the start and end of a string
keyupCaptures keyboard input
"Enter"Detects if the Enter key was pressed

✅ Summary

In Step 9.2, you learned how to:

  • Understand and interact with the DOM.
  • Create, edit, and remove elements dynamically.
  • Style buttons and inputs for a clean interface.
  • Listen for user input via clicks or the keyboard.

🎯 You’ve now built a mini app — interactive, user-friendly, and entirely made with vanilla JavaScript.

Post Views: 772

Condividi:

  • Condividi su Facebook (Si apre in una nuova finestra) Facebook
  • Condividi su X (Si apre in una nuova finestra) X
Javascript Coding

Navigazione articoli

Previous post
Next post

Francesco

My name is Francesco Boschi, originally from Italy and currently based in the United States. For over twenty years, I’ve worked as a manager and consultant across diverse sectors — from education and cultural institutions to the food industry — developing skills in operational management, strategic consulting, and complex problem-solving. In recent years, I’ve combined this experience with a strong passion for software development, creating custom tools designed to simplify workflows and meet real business needs.

Relocating to the U.S. marks the beginning of a new chapter: a personal and professional decision driven by the desire to be close to my son and to embrace new challenges in a different environment. Today, my goal is to turn my experience into meaningful solutions, blending strategic vision with technical expertise to help people and organizations work more effectively.

I enjoy moving between different worlds, adapting tools and approaches to people and contexts. I bring leadership, flexibility, attention to detail, analytical thinking, and a strong problem-solving mindset — along with a deep curiosity to learn and grow. Above all, I believe in sharing: I’m always eager to offer my experience to support the growth of others.

Related Posts

Coding

Coding – Step 10.4 – Edit & Remove Tasks (with closing: Python vs PHP and Large Data)

Posted on 17 Agosto 202517 Agosto 2025

Add edit and delete features to your Python To-Do app. Learn the differences between Python and PHP and how to approach large data.

Condividi:

  • Condividi su Facebook (Si apre in una nuova finestra) Facebook
  • Condividi su X (Si apre in una nuova finestra) X
Read More
Coding

Coding – Step 14.3 – Ubuntu – Managing Files, Folders, and Permissions

Posted on 18 Ottobre 202518 Ottobre 2025

Practical guide to managing files, folders, and permissions in Ubuntu with clear examples and respectful Windows comparisons.

Condividi:

  • Condividi su Facebook (Si apre in una nuova finestra) Facebook
  • Condividi su X (Si apre in una nuova finestra) X
Read More
Coding

ArchPilot – Step 1: Users & Roles, End-to-End (Architecture, Database, and Cross-Framework Code)

Posted on 6 Novembre 20256 Novembre 2025

ArchPilot: cross-framework ERP/CRM reference (users, roles, permissions, audit, SSO) with a canonical PostgreSQL schema and side-by-side code for Laravel, Django, Spring Boot, ASP.NET Core, Node/Express, and Drupal, architecture, ERP, CRM, RBAC, SSO, PostgreSQL, MySQL, SQL Server, Laravel, Django, Spring Boot, ASP.NET Core, Node.js, Express, Drupal, audit logging, microservices, MVP

Condividi:

  • Condividi su Facebook (Si apre in una nuova finestra) Facebook
  • Condividi su X (Si apre in una nuova finestra) X
Read More

Iscriviti alla nostra Newsletter

🤞 Let's keep in touch

We do not send spam! Read our Privacy policy for more information.

Controlla la tua casella di posta o la cartella spam per confermare la tua iscrizione

Cerca nel sito

©2026 This is my space, where experience meets the will to start over. | WordPress Theme by SuperbThemes