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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:42:33+00:00 2026-06-14T09:42:33+00:00

I have 5 divs in a row. They all have 1 background on page

  • 0

I have 5 divs in a row. They all have 1 background on page load. I want to change the BG of the div hovered, and all previous identical divs. I’m not sure how to go about that

div { style="background: url(images/red)"}

<div class="myDiv">One</div>
<div class="myDiv">Two<div>
<div class="myDiv">Three</div>
<div class="myDiv">Four</div>
<div class="myDiv">Five</div>

so when div THREE above is hovered on, I want divs ONE, TWO, and THREE to have a blue background.

if I did

$('.myDiv').hover(function(){
    $(this).prev('.myDiv').css({...});
});

It would only affect the first previous one. Can anyone point me in the right direction?

  • 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-14T09:42:34+00:00Added an answer on June 14, 2026 at 9:42 am

    Here is the Javascript:

    $('.myDiv').hover(function(){
        $(this).prevAll('.myDiv').andSelf().css({...});
    });
    

    And you also have a mistake in your markup, the second div isn’t closed.:

    <div class="myDiv">One</div>
    <div class="myDiv">Two</div>
    <div class="myDiv">Three</div>
    <div class="myDiv">Four</div>
    <div class="myDiv">Five</div>
    

    Working Example: http://jsfiddle.net/snynL/

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

Sidebar

Related Questions

I have 7 divs in a row with all very little content. I want
I have 3 divs in one row <div id=left></div> <div id=middle></div> <div id=right></div> here's
I have to follow divs: <div id=cont> <div class=row> <div class=col>1</div> <div class=col>example.com</div> <div
I have some divs holidng images I want to display. They are within a
I have several divs on a page that all have the same width but
I have some divs on my page that when a link is clicked they
I have to create a row of 3 divs with varying heights, but they
I have 4 divs in a horizontal row. I want to put space between
I have divs that I want to display at specific times throughout the day.
Have three divs in a container that I want to float over a large

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.