我无法从.li
到达button
标签。我怎么在JS中做呢?
<div class="li">
<li> Apple <button>Delete</button></li>
<li> Ball <button>Delete</button></li>
<li> Cat <button>Delete</button></li>
<li> Dog <button>Delete</button></li>
</div>
button
是li
标签的兄弟元素还是子元素?我在控制台得到undefined
。
您可能需要先查询父div,然后获取所有按钮
let buttons = document.body.querySelector(".li").getElementsByTagName("button");
// test if we've queried the buttons successfully
buttons[0].style.display = "none";