Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 729795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:50:19+00:00 2026-05-14T06:50:19+00:00

I am having trouble traversing from a bookmark has tag in jquery. Specifically, the

  • 0

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 (<h2 class="title"><a href="#co...)

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:50:20+00:00Added an answer on May 14, 2026 at 6:50 am

    The $('#comment-1') selector selects the <a> element. The next method looks at the next sibling node of that element. There is no such node with a class of “title”, so you get an empty result. In your example, the only sibling node of <a> is the div with class=”comment”. To find the <h2 class="title"> element, you can use e.g.:

    $(window.location.hash).next().children('.title')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having trouble accessing javascript code in a mixed html/js ajax response. jQuery ajax doc
Having trouble getting to this span tag to add and remove HTML content for
Having trouble inheriting from a template class. Looks something like this: template<typename type> class
Having trouble understanding how to filter an images table by tag information in a
Having trouble understanding. With the following css : .bloc .field:nth-last-child(2){ ...some values... } and
Having trouble framing this assertion in Rspec for my rails app. A User has
Having trouble with the following segment of code. I'm getting a parameter count mismatch.
I'm basically having a bit of trouble with traversing through an unordered list and
Having trouble with selectors/transversing. Basically, I want the popup div to open when the
Having trouble getting the oauth access token and secret exchanged from the request tokens

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.