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

  • Home
  • SEARCH
  • 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 8551385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:11:02+00:00 2026-06-11T14:11:02+00:00

I asked similar question here jquery how to change only one parent on hover

  • 0

I asked similar question here

jquery how to change only one parent on hover

But it’s not what I want.
so , I re-code and post it again here

I would like to change only one parent on <a> when I hover over <p> tags. The code is:

$('.hover').each(function () {
 $(this).parent().hover(function () {
        $('p').parent(this).css('background-color','red');
    }, function () {
        $('p').parent(this).css('background-color','black');
 });
});

And the HTML is:

<ul>
   <li><a href='#'>1</a> <p class='hover'>A</p></li>
   <li><a href='#'>2</a> <p class='hover'>B</p></li>
   <li><a href='#'>3</a> <p class='hover'>B</p></li>
   <li><a href='#'>4</a> <p class='hover'>X</p></li>
   <li><a href='#'>5</a> <p class='hover'>Y</p></li>
   <li><a href='#'>6</a> <p class='hover'>Z</p></li>
</ul>

What i want is when i hover “A” and “1” is change and other not change
and when i hover on “b” and “2” is change other not change also

sorry , im really new in jquery.

  • 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-11T14:11:03+00:00Added an answer on June 11, 2026 at 2:11 pm

    there is no need of .each, use .prev

    $('.hover').hover(function () {
            $(this).prev('a').css('background-color','red');
        }, function () {
            $(this).prev('a').css('background-color','yellow');
     });
    

    alternative : you can use .parent().children('a') OR
    .siblings('a') instead of .prev('a')

    ​
    Demo

    Update

    If you want to use .each ( as you mentioned in comment ) then do below.

    $('.hover').each(function () {
     $(this).parent().hover(function () {
            $(this).children('a').css('background-color','red');
        }, function () {
            $(this).children('a').css('background-color','yellow');
     });
    });
    

    Demo using .each

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

Sidebar

Related Questions

There was a similar question asked here three years ago, but I want to
My question is similar to the one being asked here , but I am
I asked a very similar question here but since it is such a fundamental
A similar question was asked here: PHP variable like $myvar-test is not valid? And
A similar question was asked here but without a satisfying answer. I'm trying to
Somebody asked similar question not long ago. But nobody answered comprehensively. Assume I have:
I asked a similar question here a while back but all the answers were
I already asked a similar question but this one is a bit different/specific: I'm
I have asked a similar question before here , but after much thought, and
I've asked a similar question here: How to enforce one method in WCF Rest

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.