如何使用父母ID获得孩子的ID?

问题描述 投票:-5回答:1
<div id="board">
  <div id="sss" class="card"><img src="img/sss" alt="sss"></div>
  <div id="ssa" class="card"><img src="img/sss" alt="sss"></div>
  <div id="ssb" class="card"><img src="img/sss" alt="sss"></div>
</div>

如何使用"sss"获取ID "ssa""ssb""board"的列表?

javascript html dom
1个回答
1
投票

document.querySelectorAll('#board > div').forEach(dv=>console.log(dv.id))
<div id="board">
  <div id="sss" class="card"><img src="img/sss" alt="sss"></div>
  <div id="ssa" class="card"><img src="img/sss" alt="sss"></div>
  <div id="ssb" class="card"><img src="img/sss" alt="sss"></div>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.