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 8630753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:07:10+00:00 2026-06-12T09:07:10+00:00

I have a nav menu bar based on twitter bootstrap that I want to

  • 0

I have a nav menu bar based on twitter bootstrap that I want to apply scrollspy to for hightlighting. i include the menu into multiple pages using a normal php include. therefore I am linking to files using their filename plus bookmark (e.g. products.php#foo).

but the way that scrollspy wants urls to work is to use the format <a href="#id-of-target">my link</a>, so that when <div id="id-of-target"> scrolls into view, the href is matched based on the href attrib and gets the active class put on it.

which means that if I have a link like <a href="products.php#my-catalogue">my catalogue</a> then it won’t match the id and the link won’t highlight.

i couldn’t work out how to modify scrollspy so that it only matches on the id after the # in the href value.

  • 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-12T09:07:12+00:00Added an answer on June 12, 2026 at 9:07 am

    New Answer

    (1) You can add a data-target to your link like so:

    <a href="products.php#my-catalogue" data-target="#my-catalogue">my catalogue</a>
    

    (2) Bootstrap uses either your href or data-target in your nav links to find the target regions on the page. If you have something like products.php#my-catalogue the regular expression checker in the code will fail. But if you do a trim beforehand it will work

    In scroll spy bootstrap code you can change (in the “refresh” function in ScrollSpy):

    .map(function () {
        var $el = $(this)
                  , href = $el.data('target') || $el.attr('href')
                  , $href = /^#\w/.test(href) && $(href)
    

    to

    .map(function () {
        var $el = $(this)
                  , href = $el.data('target') || $el.attr('href')
                  , trimmed = href.match(/#\w*/)[0]
                  , $href = /^#\w/.test(trimmed) && $(trimmed)
    

    and then having something like

    <a href="products.php#my-catalogue">my catalogue</a>
    

    should be no problem


    Old Answer

    Maybe you could try editing the scroll spy selector in the bootstrap js code?

    There is a line (around 1442 for me):

    selector = this.selector
          + '[data-target="' + target + '"],'
          + this.selector + '[href="' + target + '"]'
    

    If changed to

     selector = this.selector
          + '[data-target="' + target + '"],'
          + this.selector + '[href="products.php' + target + '"]'
    

    Could solve your problem

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

Sidebar

Related Questions

I have a nav menu bar based on twitter bootstrap that uses scrollspy to
I have a nav bar that has a dropdown menu made with styled tags.
I would like to have a search box integrated into a nav bar that
I have a twitter bootstrap nav bar, but evertime I navigate on a link
Using twitter bootstrap. on the site i have a top nav bar consisting of
I have a header with a logo and a nav menu. I want the
I have a drop down menu in my nav bar but it has quite
I have to build a WordPress theme based on Twitter Bootstrap. For now I've
I am trying to make a CSS based nav bar that converts a UL/LI
I have nav a bar on my site but I want to put rounded

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.