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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:17:55+00:00 2026-05-30T22:17:55+00:00

<div id=item> <div class=action> Oh! Look, a squashed pea! </div> <img class=picture src=example> </div>

  • 0
<div id="item">
    <div class="action">
        Oh! Look, a squashed pea!
    </div>
    <img class="picture" src="example">
</div>

Using jQuery, when hovering over the image I need to the the DIV with the class name ‘action’.
The hovering part I have down-pat and works fine, but I’m struggling with the selector part.

I’ve tried selecting the parent, then sibling with ‘action’ class with no luck…

EDIT: more info I should have added but clumsily didn’t trying to make it easier to read – my bad.

<div id="item"> 
    <div class="action"> 
        <span>Oh! Look, a squashed pea!</span>
        <button id="add">Hello</button>
    </div> 
    <img class="picture" src="example"> 
</div> 

I’m still after a reference to the DIV with the .action class applied WITHOUT referencing any ID’s.

  • 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-30T22:17:56+00:00Added an answer on May 30, 2026 at 10:17 pm
    $("#item img")
        .on("mouseover", function(){
        var prevAction = $(this).prev();
        prevAction
            .css("background-color","red");
    });
    

    We use prev() to select the immediately preceding element. (We then proceed to set its background color to red, but that’s the part you change). In this case, the element you want to select is stored in the variable prevAction.

    EDIT: For your update:

    $("img.picture")
        .on("mouseover", function(){
        var prevAction = $(this).prev();
        prevAction
            .css("background-color","red");
    });
    

    Instead of selecting an image within the div with the id item, we select the image with the class picture. This may conflict with other elements if you have images with the same class outside of those #item divs. In which case, you could probably make the selector more specific:

    $("div img.picture")
    

    This will select images with the class picture inside any div element (regardless of id or class).

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

Sidebar

Related Questions

I can select the first item in the div using $('.class:first') Now since I
Say I have jquery code like this: html += '<div class=index>' + item.index +
I'm trying to reproduce this html using jquery on a click event. <div class=comments_action_207>
There's a HTML: <div class=test> <ul> <li>Item 1</li> <li>Item 2</li> </ul> </div> And a
I am generating menu with such tags: <div class=animatedtabs> <ul> {% for item in
When I run this line of code in my view, <%= image_tag(item.picture.url(:medium), :class =>
I have a bunch of these on a page: <div class=item id=555> <div class=wrapper>
Page has menu items that would replace a 'div id=foo_(current menu item)' with 'div
Item 1 <div id=i2><span id=e2>Item 2</span></div> When I click on Item 1 it should
How do I get the div from within this (the last) list item? Currently

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.