firstChildオブジェクトが次のコードでundefinedを返すのはなぜですか?私はを省略すると、child = child.nextSibling;Javascript:firstChildオブジェクトは未定義を返します
あなたが何か間違ったことをやっているので、次の行で、私はnextSibling
divs = $('.post')
for(ind in divs){
div = divs[ind];
var child = div.firstChild;
child = child.nextSibling; //omitting this causes undefined
alert (child.innerHTML);
}
がHTML
.....
<div class="post">
<h4>
HEADER
</h4>
<div class="content">
<p>
text goes here
</p>
</div>
</div>
......
を。 $ .each()または少なくとも.lengthベースのforループを使用してください。 – dandavis
あなたが実際に 'div'がループの内側にあるものログインしましたか?あなたは既にjQueryの、なぜあなたはちょうど '.children()'と '.next()'のような、そのメソッドを使用していない使用しているので、あなたはjQueryの – epascarello
とin'ため '使用することを学んだ場所がわかりませんか? $ - - 0.02 ... – Barmar