jquery にタグがあるブックマークからトラバースするのに問題があります。具体的には、次の HTML:
<a id="comment-1"></a>
<div class="comment">
<h2 class="title"><a href="#comment-1">1st Post</a></h2>
<div class="content">
<p>this is 1st reply to the original post</p>
</div>
<div class="test">1st post second line</div>
</div>
URL (site.com/test.html#comment-1) にブックマーク ハッシュタグを使用してページが表示された場合、class = "title" の場所にトラバースしようとしています。以下は、テストに使用しているコードです。
if(window.location.hash) {
alert ($(window.location.hash).nextAll().html());
}
正常に実行され、適切な html ( <h2 class="title"><a href="#co...
)が返されます。
問題は、セレクターを追加すると ( $(window.location.hash).next('.title').html()
) null の結果が得られることです。これはなぜですか?nextAll は正しい Traversing 関数ではありませんか? (私も試してみました next+find 無駄に)
ありがとう!