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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:54:25+00:00 2026-05-14T19:54:25+00:00

I am trying to create a function to change the class on a series

  • 0

I am trying to create a function to change the class on a series of 5 list elements depending on which has been clicked. The goal is to change the style of the element depending on which one is the current element.

I had tried something like this:

function addClass(obj)
{
 obj.className="highlight";
}

and then added this to my elements:

 onclick="addClass(this);

but this only added the class to the first element in the list and then did not remove the class when a different one was clicked.

My list elements look like this:

     <ul id="circularMenu">

        <a href="#strategy" onclick="addClass(this);"><li id="strategy_link"><h3>Strategy</h3></li></a>
        <a href="#branding"><li id="branding_link" onclick="addClass(this);"><h3>Branding</h3></li></a>
        <a href="#marketing"><li id="marketing_link" onclick="addClass(this);"><h3>Marketing</h3></li></a>
        <a href="#media"><li id="media_link" onclick="addClass(this);"><h3>Media</h3></li></a>
        <a href="#management"> <li id="management_link" onclick="addClass(this);"><h3>Management</h3></li></a>

     </ul>

When an item is clicked the url changes, maybe this could be the way to set up the function to change classes depending on the url? I am very new with javascript any ideas on how to make this work would be greatly appreciated.

The current way I have it coded is to change each item when hovered, but I would like the change to remain until a different item is clicked. It can be viewed here: http://perksconsulting.com/dev/capabilties.php The items I am referring to are the black dots on the left side of the page.

  • 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-14T19:54:26+00:00Added an answer on May 14, 2026 at 7:54 pm

    First, you should use the jQuery addClass() method. You don’t need to write your own (your addClass() implementation is buggy, by the way).

    Try this:

    function selectInList(obj)
    {
        $("#circularMenu").children("a").removeClass("highlight");
        $(obj).addClass("highlight");
    }
    

    Then:

        <ul id="circularMenu">
            <a href="#strategy" onclick="selectInList(this);"><li id="strategy_link"><h3>Strategy</h3></li></a>
            <a href="#branding"><li id="branding_link" onclick="selectInList(this);"><h3>Branding</h3></li></a>
            <a href="#marketing"><li id="marketing_link" onclick="selectInList(this);"><h3>Marketing</h3></li></a>
            <a href="#media"><li id="media_link" onclick="selectInList(this);"><h3>Media</h3></li></a>
            <a href="#management"> <li id="management_link" onclick="selectInList(this);"><h3>Management</h3></li></a>    
         </ul>
    

    Or even better, keep your html clean and let jQuery simplify things:

        <ul id="circularMenu">
            <a href="#strategy"><li id="strategy_link"><h3>Strategy</h3></li></a>
            <a href="#branding"><li id="branding_link"><h3>Branding</h3></li></a>
            <a href="#marketing"><li id="marketing_link"><h3>Marketing</h3></li></a>
            <a href="#media"><li id="media_link"><h3>Media</h3></li></a>
            <a href="#management"><li id="management_link"><h3>Management</h3></li></a>
        </ul>
    

    Then, somewhere in your page:

    $(document).ready(function()
    {
       $("#circularMenu").children("a").click(function() { selectInList(this) });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 394k
  • Answers 394k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your use of REGEXP is pretty close. This should work:… May 15, 2026 at 2:12 am
  • Editorial Team
    Editorial Team added an answer Having recently handled pagination with Code Igniter (php framework), the… May 15, 2026 at 2:12 am
  • Editorial Team
    Editorial Team added an answer in view <DataGrid ItemSource="{Binding MyItems}" SelectedItem = "{Binding MyCurrentItem}" >… May 15, 2026 at 2:12 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.