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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:20:45+00:00 2026-06-18T20:20:45+00:00

How do I Change background color to green when link is clicked and keep

  • 0

How do I Change background color to green when link is clicked and keep the color green until I click the link again then the color must be white

I have this code so far:

    <% foreach (var group in Model.Results)
       { %>       

         <div id="group-select<%: group.GroupId %>" style="width:95%; height:50px; border:solid 1px black; margin:5px;" >
            <h3><a href="javascript:OnGroupClicked(<%: group.GroupId %>)" id="changer<%: group.GroupId %>"  ><%: group.Name %></a></h3> 
         </div>

    <% } %>

and the JS:

<script type="text/javascript">   
function OnGroupClicked(groupId) {
  $("#changer" + groupId).on("click", function (e) {
    e.preventDefault();
    var body = $('#group-select' + groupId),
        green = "rgb(0, 128, 0)",
        white = "rgb(255, 255, 255)";

    if (body.css("backgroundColor") !== green) {
      body.css("backgroundColor", green);
    } else {
      body.css("backgroundColor", white);
    }
  });
}
</script>

can some one help me please?
the color green wil show that a specific group is selected and when it is white it is NOT selected. So when the page first loads up it will be white. I click on it and it is green and stays green until I click it again.

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-18T20:20:47+00:00Added an answer on June 18, 2026 at 8:20 pm

    You could do something like this:

    http://jsbin.com/evupih/1/edit

    The problem with your code is, you check for the hex value. But if you read the backgroundColor, you will get the rgb value 😉

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

Sidebar

Related Questions

I am have text that when you click it, the background-color turns green, and
Goal: Have first input box background-color change to green (on target.html) after redirecting. It
How can I change background color with jQuery .click(function(){ div normal with Green color,
I am able to change the background-color of this element: <div onmouseover=this.style.backgroundColor='blue' onmouseout=this.style.backgroundColor='red' style=background-color:green;
I read this post but I can't get it working: Change Background Color... I
I want to change the background color of the child which is clicked in
I was trying to change cell's background color with custom formatter like this: var
Is possible change background-color on same td in fullcalendar? for example: I like have
I have a Yahoo Weather problem. I'm trying to change the background color by
With this code fragment, I would expect the label to have a background color

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.