简体   繁体   中英

HTMLCollection will log to console, but logging .count returns undefined?

What's the deal?

var blocks = document.getElementsByClassName('code-block');

Just grabbing all my textareas.

console.log(blocks);

returns a HTMLCollection with all 14 items.

console.log(blocks.count);

returns

undefined

I did try setTimeout but that didn't help. I'm also inside a document.ready function and in the global scope. If it makes a difference, all my textareas are inside of a .collapsible div from Materialize.css so they are not initially visible.

blocks.length 

哇,这是我最近一直在与Swift一起工作的原因。哈哈。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM