Is it possible to use querySelector() on a dynamically created element?

拈花ヽ惹草 提交于 2019-12-11 22:21:18

问题


I'm using appendHtml() in a loop to dynamically add li elements (with unique IDs in the string) to a ul. When I need to access these dynamically created li elements by their IDs to, for example, create nested lists, querySelector() returns null. If I should be able to do this, then there could very well be bugs in my code. But I want to make sure this is the case.


回答1:


It doesn't matter how elements are added, if the are part of the DOM querySelector can find them.



来源:https://stackoverflow.com/questions/26394086/is-it-possible-to-use-queryselector-on-a-dynamically-created-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!