Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Task List Navigation</title> <style> .task { margin: 10px; padding: 10px; border: 1px solid #ccc; } .completed { text-decoration: line-through; color: gray; } </style> </head> <body> <div class="task-list"> <div class="task"> <p>Task 1: Do the laundry</p> <button class="complete-task">Complete Task</button> </div> <div class="task"> <p>Task 2: Buy groceries</p> <button class="complete-task">Complete Task</button> </div> <div class="task"> <p>Task 3: Clean the house</p> <button class="complete-task">Complete Task</button> </div> </div> <script> document.querySelectorAll('.complete-task').forEach(button => { button.addEventListener('click', () => { const task = button.parentElement; task.classList.add('completed'); button.disabled = true; const nextTask = task.nextElementSibling; if (nextTask) { document.body.insertAdjacentHTML('beforeend', `<p>Next task: ${nextTask.querySelector('p').textContent}</p>`); } else { document.body.insertAdjacentHTML('beforeend', `<p>No more tasks available</p>`); } }); }); </script> </body> </html>