Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>
    <div id="app">
      <input type="text" id="taskInput" placeholder="Agregar nueva tarea" />
      <button id="addButton">Agregar Tarea</button>
      <ul id="taskList"></ul>
    </div>
              
            
!

CSS

              
                body {
        font-family: Arial, sans-serif;
        background-color: #f4f4f4;
        margin: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
      }

      #taskInput {
        padding: 10px;
        font-size: 16px;
      }

      #taskList {
        list-style: none;
        padding: 0;
      }

      .taskItem {
        background-color: #fff;
        margin: 5px 0;
        padding: 10px;
        border-radius: 5px;
        display: flex;
        justify-content: space-between;
        align-items: center;
      }

      .deleteButton {
        background-color: #e74c3c;
        color: #fff;
        border: none;
        padding: 5px 10px;
        border-radius: 3px;
        cursor: pointer;
      }

      #addButton {
        background-color: #3498db;
        color: #fff;
        border: none;
        padding: 10px;
        border-radius: 5px;
        cursor: pointer;
      }
              
            
!

JS

              
                document.addEventListener("DOMContentLoaded", function () {
        const taskInput = document.getElementById("taskInput");
        const taskList = document.getElementById("taskList");
        const addButton = document.getElementById("addButton");

        // Cargar tareas almacenadas en localStorage al cargar la página
        const savedTasks = JSON.parse(localStorage.getItem("tasks")) || [];
        savedTasks.forEach((task) => addTaskToList(task.text));

        // Función para agregar una tarea a la lista
        function addTaskToList(taskText) {
          const taskItem = document.createElement("li");
          taskItem.className = "taskItem";

          const taskSpan = document.createElement("span");
          taskSpan.textContent = taskText;
          taskItem.appendChild(taskSpan);

          const deleteButton = document.createElement("button");
          deleteButton.className = "deleteButton";
          deleteButton.textContent = "Eliminar";
          deleteButton.addEventListener("click", function () {
            taskItem.remove();
            deleteTaskFromLocalStorage(taskText);
          });
          taskItem.appendChild(deleteButton);

          taskList.appendChild(taskItem);
        }

        // Evento para agregar una tarea al hacer clic en el botón
        addButton.addEventListener("click", function () {
          const taskText = taskInput.value.trim();

          if (taskText !== "") {
            const newTask = { text: taskText };
            addTaskToList(newTask.text);
            updateLocalStorage(newTask);
            taskInput.value = "";
          }
        });

        // Función para actualizar el almacenamiento local con las tareas actuales
        function updateLocalStorage(newTask) {
          const savedTasks = JSON.parse(localStorage.getItem("tasks")) || [];
          const updatedTasks = [...savedTasks, newTask];
          localStorage.setItem("tasks", JSON.stringify(updatedTasks));
        }

        // Función para eliminar una tarea del almacenamiento local
        function deleteTaskFromLocalStorage(taskText) {
          const savedTasks = JSON.parse(localStorage.getItem("tasks")) || [];
          const updatedTasks = savedTasks.filter((task) => task.text !== taskText);
          localStorage.setItem("tasks", JSON.stringify(updatedTasks));
        }
      });
              
            
!
999px

Console