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

  • Home
  • SEARCH
  • 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 8021349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:57:15+00:00 2026-06-04T21:57:15+00:00

I am trying to use scrollspy, but at http://twitter.github.com/bootstrap/javascript.html#scrollspy , the example seems not

  • 0

I am trying to use scrollspy, but at http://twitter.github.com/bootstrap/javascript.html#scrollspy, the example seems not working, and also there is a headsup:

Heads up! Navbar links must have resolvable id targets. For example, a <a href="#home">home</a> must correspond to something in the dom like <div id="home"></div>. 

Th problem is scrollspy is just one functionality in my site which happens to be always loaded even when there is no id targets in the page, and this results in error as predicted by the headsup.

The error:

uncaught exception: Syntax error, unrecognized expression: #

The same error also happens to when I am using scrollTo.js plugin.

So I am trying to add a condition, to activate scrollspy only if there is id targets in the DOM.

  $('.nav-scrollspy').each(function() {
              var $nav = $(this).find('a');
                var linkHref = $nav.attr('href').split('#')[1];
                if ($('#' + linkHref).length) {
                $(this).scrollspy();
                }
  });

The above fails, because I think I should filter to only the first found hash from the link.

Any hint to the issue or another better way would be very much appreciated.
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-06-04T21:57:17+00:00Added an answer on June 4, 2026 at 9:57 pm

    Change this line

    if ($('#' + linkHref).length) {
    

    to

    if ($.trim(linkHref).length > 0) {
    

    and it should work fine.

    The reason for this after this line

    var linkHref = $nav.attr('href').split('#')[1];
    

    linkHref is a string

    so wrapping it around $ object is not necessary at all in this case and can cause error, I am using $.trim to trim off any whitespace which is not mandatory either, but a good practice in cases like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I'm trying to use scrolltop method and event.preventDefault is not working properly. What I'm
trying to use regex to replace any white space with &nbsp;, inside of example
I am trying use javascript regular expressions to do some matching and I found
I'm trying to do the classic Sticky Element in reverse. See http://imakewebthings.com/jquery-waypoints/sticky-elements/ for an
I'm trying use an object which wasn't available until SDK level 5. It seems
I am trying use Thread but i have some problem (I am beginner at
I'm trying use double type in openCL, but doesn't work anyway, i want use
I'm trying use the modulo operator (%) on long longs, and it seems to
Im trying use a Java annotation in a Groovy class but have trouble to

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.