Javascript 计数没有名称或ID的通用DIV标记

Javascript 计数没有名称或ID的通用DIV标记,javascript,html,css,Javascript,Html,Css,如何使用javascript计算DIV标记的数量?唯一的属性将始终是style=font系列:Courier New 页面中还有其他DIV。我只是想针对那些拥有style=font家族的人:Courier New; 有什么帮助吗?您可以使用jQuery: console.log($("[style='font-family:Courier New;']").length); 您正在寻找querySelectorAll var courier=document.queryselectoral'

如何使用javascript计算DIV标记的数量?唯一的属性将始终是style=font系列:Courier New

页面中还有其他DIV。我只是想针对那些拥有style=font家族的人:Courier New;
有什么帮助吗?

您可以使用jQuery:

console.log($("[style='font-family:Courier New;']").length);
您正在寻找querySelectorAll

var courier=document.queryselectoral'div[style=font-family:courier-New;]; 对于var i=0,len=courier.length;i一些没有jQuery的文本:document.getElementsByTagName'div'.length;这将统计页面中的所有div。我试图只针对那些样式=字体系列:Courier New;尝试使用XPath,它使您能够根据属性匹配标记:选择器字符串是否应为div[style=font-family:Courier New;]?您可以在=:document.queryselectoral'div[style*=font-family:Courier New;]'之前添加一个*;这将允许这样的元素:一些文本
console.log($("[style='font-family:Courier New;']").length);