I can get the count of all descendants of an element, but I can't seem to target just the immediate children. Here's what I have at the moment.
var sectionCount = document.getElementById("window").getElementsByTagName("section").length;
I've played with other stuff and different syntax, but I can't seem to get it.
The jQuery equivalent would be:
var sectionCount = $("#window > section").length;
But I need to do this javascript only.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…