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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:39:36+00:00 2026-06-09T11:39:36+00:00

I caught a flaw in this script I’m using; It’s calling the global ‘a’

  • 0

I caught a flaw in this script I’m using; It’s calling the global ‘a’ tag – which is killing me.

What it the proper way to define a specific classes link within the ‘a’ tag within the snippet below?

var allLinks = document.getElementsByTagName('.mainnav');

Clearly that didn’t work; either did .mainnav a

Full snippet:

var ss = {
  fixAllLinks: function() {
    // Get a list of all links in the page
    var allLinks = document.getElementsByTagName('.mainnav');
    // Walk through the list
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if ((lnk.href && lnk.href.indexOf('#') != -1) && 
          ( (lnk.pathname == location.pathname) ||
        ('/'+lnk.pathname == location.pathname) ) && 
          (lnk.search == location.search)) {
        // If the link is internal to the page (begins in #)
        // then attach the smoothScroll function as an onclick
        // event handler
        ss.addEvent(lnk,'click',ss.smoothScroll);
      }
    }
  },

Update: After swapping out different tags; and trying to call with classes the script stopped functioning. Here’s the full plugin; http://www.kryogenix.org/code/browser/smoothscroll/ I just want to use this with specific classes as opposed to all ‘a’ tags.

Suggestions; 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-09T11:39:37+00:00Added an answer on June 9, 2026 at 11:39 am

    .mainnav isn’t a tag, so getElementsByTagName won’t work. Perhaps you’re looking for:

    var allLinks = document.getElementsByClassName('mainnav');
    

    https://developer.mozilla.org/en-US/docs/DOM/document.getElementsByClassName

    or in jQuery:

    $('.mainnav');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Asserts can't be caught. This is good because some errors I don't want to
Why are some exceptions in Java not caught by catch (Exception ex) ? This
This issue has caught me out once again. Could someone provide a technical explanation
Can exceptions be caught inside a using block, and if so what is the
I get: TemplateSyntaxError at /blog/post/test Caught NameError while rendering: global name 'forms' is not
What is the best way to log the exceptions caught in WCF service hosted
Is there a way to find what exception was caught by .NET code from
I just caught myself doing this: <table> <tr> <th>Code</th> <th>Enabled</th> <th>Percentage</th> <th>Amount</th> <th>Start</th> <th>End</th>
I'm getting caught up on PHP again, and have the following update code. This
I am getting this error when i visit my page: Caught AttributeError while rendering:

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.