我尝试使用www.example.com编辑特定动态添加的DIV的innerHTMLe.target但它返回Null第一个
ubof19bj1#
//im adding e.listener to a whole DIV and targetting specific elements inside that div todoList.addEventListener("click", (e)=>{ let inputText = e.target.closest(".todo").querySelector(".input-text") console.log(inputText.innerHTML) })
<ul class="flex todo-list flex-col todo-list h-72 flex-1 overflow-auto"> <li class="todo flex justify-between bg-white/30 p-2 px-2 rounded-r-full my-1"> <div class=""> <span class="input-text">Hello World</span> </div> <div class="flex gap-x-1"> <button class="done-todo-btn bg-[#E94560] font-bold px-2 rounded-xl">Done</button> <button class="edit-todo-btn bg-[#16003B] font-bold px-2 rounded-xl">Edit</button> <button class="del-todo-btn bg-[#0F3460] font-bold px-2 rounded-xl">Delete</button> </div> </li> </ul>
1条答案
按热度按时间ubof19bj1#