<h1>나의 todo list</h1>
<p>1. 오늘 저녁에는 부대찌게를 끓여 먹겠다.<button type="button">삭제</button></p>
<p>2. 후식으로 슈팅스타를 먹겠다.<button type="button">삭제</button></p>
<p>3. 자기 전에 반드시 내일 아침 메뉴를 생각해두겠다.<button type="button">삭제</button></p>
const p = document.querySelectorAll("p");
const rmBtn = document.querySelectorAll("button");

Array.prototype.forEach.call(p, (text) => {
  text.addEventListener("click", (e) => {
    alert(e.target.innerText.slice(0, -2));
  });
});

for (const item of rmBtn) {
  item.addEventListener("click", (e) => {
    let result = confirm("삭제하시겠습니까?");
    if (result == true) {
      item.parentElement.remove();
    }
    e.stopPropagation();
  });
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.