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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:54:45+00:00 2026-05-30T21:54:45+00:00

Hello Stackoverlowers! I need to sort out my div’s and ensure that the background

  • 0

Hello Stackoverlowers!

I need to sort out my div’s and ensure that the background color of a div changes when a certain hyperlinks are closed.

My JS mark up is:

<script>
$("bgcolor").click(function(){
    $("#blackandwhite").animate(
        {backgroundColor: '#000000'},
        "slow");}
);
}

My HTML is:

<div id="blackandwhite"> text here </div>

My CSS is:

#blackandwhite { width:100%; #FFFFFF; }

The link structure I am using to trigger the div to change color is like this:

<li><a href="#secondpagename" class="bgcolor"> link text </a></li>

Really cannot work out why it is not working and will appreciate any and all help! I feel like I am almost there.

All I want to do is to have the hyperlink change the div background. This hyperlink is also and will remain outside of the div. Any ideas?

  • 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-30T21:54:46+00:00Added an answer on May 30, 2026 at 9:54 pm

    There are two problems you need to address

    1. The selector needs to look for the class bgcolor and hence should be .bgcolor
    2. Probably need to prevent the default action of the hyperlink via e.preventDefault(). Not 100% sure about your intent here but if it’s just to change the color and not jump in the page then this is likely what you want.

    Try the following instead

    $(".bgcolor").click(function(e) {
        $("#blackandwhite").animate(
            {backgroundColor: '#000000'},
            "slow");
        e.preventDefault()
    });
    

    EDIT

    As others have pointed out jQuery doesn’t support animation out of the box. It does support direct changes of the color though via css

    $("#blackandwhite").css(backgroundColor: '#000000');
    

    If you really want color animation though there are a number of plugins available. For example

    • http://www.bitstorm.org/jquery/color-animation/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys I need to pass a string array over to a setter that
Hello following problem, i need the id attribute string for each div in a
Hello, Im working on a solution for Android that will record calls (both out
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello Guys I am trying to figure out why i am gettings this error
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello I need some help with a bug in Internet Explorer 9. I am
Hello i have a list of apartments and i need to filter them by
Hello guys i have set background image on my input text and text area
Hello new to PHP and in a bit of a bind. I need to

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.