【发布时间】:2021-11-06 21:15:24
【问题描述】:
const pokemonContainer = document.getElementById('pokemonContainer');
pokemonContainer.innerHTML += `
<div>
<section class="all-comments"></section>
</div>
`;
const allComments = document.querySelector('.all-comments');
allComments.appendChild(<h1>Hello World</h1>);
<div class="row" id="pokemonContainer"></div>
我正在尝试 querySelector('.all-cmets') 但由于它位于 pokemonContainer 中,这就是它返回未定义的原因。有人可以指导我如何查询上面给出的放在innerHTML中的东西吗?
【问题讨论】:
-
我认为你应该使用 append 而不是 innerHTML。
-
您只需要使用适当的参数调用
appendChild。 -
@IlijaIličić 我无法改变这一点,因为这是一个结对编程活动,它是由其他人编写的
标签: javascript html dom dynamic queryselector