phuocng / html-dom

Common tasks of managing HTML DOM with vanilla JavaScript. Give me 1 ⭐if it’s useful.
https://phuoc.ng/collection/html-dom
MIT License
6.52k stars 459 forks source link

delete does not take effect when remove the event handler #231

Open Levix0501 opened 2 years ago

Levix0501 commented 2 years ago

in "Attach or detach an event handler”

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Static Template</title>
    <style></style>
  </head>
  <body>
    <button id="btn1">onclick</button>
  </body>
  <script>
    function fn1() {
      alert(1);
    }
    const btn1 = document.getElementById("btn1");
    btn1.onclick = fn1;
    console.log(btn1);

    let res = delete btn1.onclick;
    console.log(res);

    console.log(btn1.onclick);
  </script>
</html>