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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:33:58+00:00 2026-06-10T06:33:58+00:00

Two questions… I have a set of DIVS with some code intended to change

  • 0

Two questions…

I have a set of DIVS with some code intended to change the colour of the clicked DIV and reset the others to their default. This works nicely… but the background colours are specified inside the javascript code. When I tried to use CSS classes, things didn’t work as they should. How can I get this second version to work so that it uses css classes to specify the colours rather than the javascript.

My second question relates to the

.parent()

part of the code and what that actually does in this context?

Any help is appreciated.

  • 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-10T06:34:00+00:00Added an answer on June 10, 2026 at 6:34 am

    Try this:

    http://jsfiddle.net/HNXjQ/4/

    HTML:

    <div id="container">
        <div class="button on">1</div>
        <div class="button off">1</div>
        <div class="button off">1</div>
        <div class="button off">1</div>
    </div>
    

    CSS:

    #container {
        position: absolute;
        top: 0;
        left: 0;
    }
    .button {
        position: relative;
        width: 100px;
        height: 100px;
        margin: 10px;
        border: 1px solid #333;
        background: green;
    }
    .on {
        background: red;
    }
    

    JS:

    $('.button').click(function(){
        $(this).siblings().removeClass('on');
        $(this).addClass('on');
    });
    
    1. You don’t need an “off”-class to get this effect.
    2. Also, in this case it’s better to use “.siblings()” which looks for it’s siblings than “.parent().find()”. (It’s basically faster / more precise)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Two questions here. I have a set of files which are usually UTF-8 with
I have two questions about Magento category naming. as I have to change the
I have two questions about binary search trees - one about the code I
Two questions only: I have a website including a section of Blog in wordpress.
I have two questions here. How can I show the header of the pop
This is two questions in one, so here we go. I have a simple
I have two questions. How can I get the spinner in the figure below
I have two questions. Does it make sense when I have to choice of
two questions today, I'm a busy bee and luckily I have an awesome community
Two questions: 1) How/where do I set the lifetime of the session cookie in

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.