このようなマークアップがあるとしましょう
<html id="test">
<body>
Some text node.
<div class="cool"><span class="try">This is another text node.</span></div>
Yet another test node.
</body>
</html>
私のjsコード
function countText(node){
var counter = 0;
if(node.nodeType === 3){
counter+=node.nodeValue.length;
countText(node);
}
else{}
}
テキストノードを数えたい場合
console.log("count text : " + countText(document.getElementById("test"));
これは私にカウントを返すはずですが、機能していません。さらに、他の条件に何を入れるべきですか。nodeType を使用したことがないので、使用に問題があります。どんな助けでも大歓迎です。