[英]JavaScript CSS Selector, Select with id
I'm trying to get the element using document.querySelectorAll()
method. 我正在尝试使用document.querySelectorAll()
方法获取元素。
var elementList = Firebug.browser.document.querySelectorAll("DIV[id='hplogo']");
when I use this with Google web site, this function returns an array with 44 elements. 当我在Google网站上使用此函数时,此函数返回包含44个元素的数组。 Please give me a solution... 请给我一个解决方案...
document.querySelectorAll
will return all elements on the page that match your query, hence why you're seeing 44 different elements. document.querySelectorAll
将返回页面上与查询匹配的所有元素,因此为什么会看到44个不同的元素。
Use document.getElementById('hplogo')
instead of querySelectorAll to get the one element with the ID that you're looking for. 使用document.getElementById('hplogo')
而不是querySelectorAll来获取具有您要查找的ID的一个元素。
Firebug.browser.document.querySelectorAll("DIV#hplogo]");
please try this. 请尝试这个。
btw what is hplogo? 顺便说一句,hplogo是什么? is it a variable or is it a selector? 是变量还是选择器?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.