如何事件目标元素并更改其innerHTML

mklgxw1f  于 2022-11-20  发布在  其他
关注(0)|答案(1)|浏览(92)

我尝试使用www.example.com编辑特定动态添加的DIV的innerHTMLe.target但它返回Null
第一个

ubof19bj

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>

相关问题