Yes: Use a loop, and count the thing you actually want (allChars
). That also has the advantage of being more robust -- it'll work with fewer rows, or more rows.
const elements = document.getElementsByClassName("news-link");
let allChars = 0;
for (const {innerHTML} of Array.from(elements)) {
allChars += innerHTML.length;
}
console.log(allChars)
<div class="ticker">
<div class="news">
<span><a href="#" class="news-link">OTHER NEWS</a></span>
<span><a href="#" class="news-link">OTHER NEWS</a></span>
<span><a href="#" class="news-link">OTHER NEWS</a></span>
<span><a href="#" class="news-link">OTHER NEWS</a></span>
<span><a href="#" class="news-link">OTHER NEWS</a></span>
<span><a href="#" class="news-link">OTHER NEWS</a></span>
<span><a href="#" class="news-link">OTHER NEWS</a></span>
</div>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…