Traversing from Bookmark Hashtags (#bookmark) in jQuery?

Posted by HipHop-opatamus on Stack Overflow See other posts from Stack Overflow or by HipHop-opatamus
Published on 2010-04-19T01:26:40Z Indexed on 2010/04/19 1:33 UTC
Read the original article Hit count: 400

I am having trouble traversing from a bookmark has tag in jquery. Specifically, the following 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>

I am trying to traverse to where the class = "title", if the page is landed on with a bookmark hashtag in the URL (site.com/test.html#comment-1). The following is my code I'm using for testing:

if(window.location.hash) {
alert ($(window.location.hash).nextAll().html());
}

It executes fine, and returns the appropriate html (

The problem is if I add a selector to it ($(window.location.hash).next('.title').html() ) I get a null result. Why is this so? Is nextAll not the correct Traversing function? (I've also tried next+find to no avail)

Thanks!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-selectors