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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:27:10+00:00 2026-05-27T10:27:10+00:00

I am quite new to writing my own jquery functions and I find debugging

  • 0

I am quite new to writing my own jquery functions and I find debugging it very difficult as the error messages aren’t too helpful when put into google.

I have a navigation menu for page anchors that when each one is clicked the screen scrolls to the anchor, the elements will change color depending on which one and the hover color will also change. Very simple really, I think.

The scrolling always works, the animate works occasionally and the hover works put usually I have to click the link twice. The return false only works on the first link you click.

This uses the scrollTo and animate-colors plugins.

Can anyone tell me what I’m doing wrong?

$(".scrolltoanchor").click(function() {
                                $('a').removeClass('selected');
                                $(this).addClass('selected');
        $.scrollTo($($(this).attr("href")), {
            duration: 750
        });

        switch ($(this).attr("id")) {
            case 'personal':
            $('.scrolltoanchor').animate({color: '#E4D8B8'});
            $(".scrolltoanchor").hover(
            function() {
            $(this).css('color', 'blue');
            },function(){
            $(this).css('color', '#E4D8B8');
            });
            break;

            case 'achievements':
            $('.scrolltoanchor').animate({color: '#ffffff'});
            $(".scrolltoanchor").hover(
            function() {
            $(this).css('color', 'red');
            },function(){
            $(this).css('color', '#ffffff');
            });
            break;

            case 'skills':
            $('.scrolltoanchor').animate({color: '#dddddd'});
            $(".scrolltoanchor").hover(
            function() {
            $(this).css('color', 'orange');
            },function(){
            $(this).css('color', '#ffffff');
            });
            break;


        }

        return false;
    });

Sorry to ask to be spoonfed, but I have followed what I believed to be the correct syntax from what I have learnt. Is there something I should know that is stopping this working as I expect?

EDIT: Sorry I forgot, I get this error on the (on average) every second click of a scrolltoanchor link

Uncaught TypeError: Cannot read property ‘0’ of undefined

I can’t spot a real pattern. Sometimes it seems to happen only on ones that havent been clicked before, sometimes not.
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-27T10:27:10+00:00Added an answer on May 27, 2026 at 10:27 am

    You’re taking the wrong approach.

    You should bind the hover handlers once, and decide the colors based on which one was clicked.

    Simplest way would probably to store the color data in a lookup table where the keys are the IDs of the elements.

    var ids = {
        personal: {
            over:'blue',
            out:'#E4D8B8'
        },
        achievements: {
            over:'red',
            out:'#ffffff'
        },
        skills: {
            over:'orange',
            out:'#dddddd'
        }
    };
    var current = ids.personal;
    

    Then bind the handlers once, and use the id of the one clicked to set the current color set.

    var scroll_anchors = $(".scrolltoanchor");
    
    scroll_anchors.hover( function() {
        $(this).css( 'color', current.over );
    },function(){
        $(this).css( 'color', current.out );
    });
    
    scroll_anchors.click(function() {
         $('a.selected').removeClass('selected');
         $(this).addClass('selected');
    
         $.scrollTo($($(this).attr("href")), { duration: 750 });
    
         current = ids[ this.id ]; // set the current color set based on the ID
    
         scroll_anchors.animate({ color: current.out });
    
         return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to sql and I'm having trouble writing this i have a
I am quite new to Selenium. Currently i am using selenium driver for writing
Iam quite new to functions in SQL and I would like to create a
I'm quite new in PHP dev and I can't find a way to solve
I'm quite new to Java Programming and am writing my first desktop app, this
Hi i m quite new to mvc and i m writing a report which
When writing code in Java, it is very helpful to embrace composition and dependency
I am quite new to Perl, and I am writing a Perl script. A
I am quite new to python programming (C/C++ background). I'm writing code where I
I'm quite new to C# so please bear with me. I'm writing a relatively

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.