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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:06:28+00:00 2026-05-28T05:06:28+00:00

I have 4 links with background color that I need to be changed when

  • 0

I have 4 links with background color that I need to be changed when I click, I use this code to change the background :

jQuery:

$(document).ready(function() {
  $('#content_area').load($('.pm_class:first').attr('href'));

  $('.pm_class').click(function() {
    var href = $(this).attr('href');
    $(this).css('background-color', '#3B581E');
    $(this).css('color', '#fff');
    $('#content_area').hide().load(href).fadeIn('normal');
    return false;
  });
});

The issue is: when I click a different link the css in my jQuery is still applied to the previous link I clicked along with the second one. I need the first to return to the original state as shown in the image below. I need it to return back to be like the “send message” and “archive” links :

jQuery issue

  • 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-28T05:06:29+00:00Added an answer on May 28, 2026 at 5:06 am

    JS functions are objects, and can be assigned member variables. These work like what in some C like languages is called a “static” local variable, meaning it retains its value between invocations.

    $('pm_class').click(function () { switchBG($(this)) });
    
    function switchBG (elem) {
        if (switchBG.prev) {
            switchBG.prev.css('background', '#ffffff');
        }
        elem.css('background', '#ffff00');
        switchBG.prev = elem;
    } 
    

    You could do the same thing with a global, but this is tidier.

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

Sidebar

Related Questions

I have links like these that I want to change: mypage.com?page=missions&id=5 mypage.com?page=hello I tried
I have some code to change how listbox act. I can change the color
I have a page that has a 4x4 grid and two squares change color
I currently have links w/ class=ajax that I want to retrieve the element with
So I have site list on certain pages that basically just have links to
I have a system that generated links to different parts of the application. I
I have the following: <div class=style-switcher id=colorChanger> <a style=background-color: #FFFFFF; data-style=arctic title=Arctic></a> <a style=background-color:
So i need to make a div a link, and have the background colour
Hi I'm new to JQuery. I have an two issues that I can't figure
Hello Stackoverlowers! I need to sort out my div's and ensure that the background

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.