在 Javascript 中,我需要使用 getElementById()
选择子元素:
#topbarsection li a {}
我已经试过了:
topbarsection = document.getElementById('topbarsection>li>a');
还有这个:
topbarsection = document.getElementById('topbarsection li a');
最佳答案
你应该使用 querySelectorAll
做这样的事情:
document.querySelectorAll('#topbarsection > li > a');
关于javascript - 使用 getElementById 查找子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27888611/