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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:28:21+00:00 2026-05-27T03:28:21+00:00

I’m still learning jQuery and would appreciate some pointers with this, as I think

  • 0

I’m still learning jQuery and would appreciate some pointers with this, as I think its simple but not sure how to do it quite.

See below my mark up generated by wordpress, its a side bar list for categorys with post count.

    <div id"sidebar-left">

        <ul id="sidebar-categories">
            <li class="list-header">Contents</li>

            <li class="cat-item cat-item-3">
                <a title="" href="x">News</a>
                <span>1</span>
            </li>
            <li class="cat-item cat-item-4">
                <a title="" href="x">Racing</a>
                <span>4</span>
            </li>
            <li class="cat-item cat-item-1">
                <a title="" href="x">Uncategorized</a>
                <span>1</span>
            </li>
        </ul>

    </div>

Now this is all cool, but my span count is positioned absolute over the top of the a tag in the li.

Which means my problem is, when I hover my a tag, and then hover the span, my hover state of the a tag disappears. So I’m trying to activate the a tag :hover when I roll over the span.

Now I have managed to do this using the jQuery below…

    $("ul#sidebar-categories li span").hover(function() {
        $("ul#sidebar-categories li a").css({ 
            backgroundColor: "464848" // a tag hover bg color
        });
    }, function() {
        $("ul#sidebar-categories li a").css({ 
            backgroundColor: "daddd7" // a tag normal bg color
        });
    });

But obviously as you can see, this will activate all the background colors of all the a tags in this sidebar-categories list.

This my attempt below to only get it to activate the a tag background color inside the current parent li. But it’s not working. I’ve also tried parent but still no worky.

    $("ul#sidebar-categories li span").hover(function() {
        $(this).children("ul#sidebar-categories li a").css({ 
            backgroundColor: "464848" // a tag hover bg color
        });
    }, function() {
        $(this).children("ul#sidebar-categories li a").css({ 
            backgroundColor: "daddd7" // a tag normal bg color
        });
    }); 

Also see screen shot below of the list ui so you can see why I need it to work this way.

Hover Status Category List UI

So as your hovering the category list, and then mouse over the ‘post count’, the a:hover pseudo class is lost.

Thanks in advance.
Josh

//// Addition my CSS

#sidebar-left ul {
    font-family: 'HelveticaNeueMediumCond';
    position: relative;
    border-bottom: 1px solid #eef0eb;
    padding: 21px 0 0;
    list-style: none;
}

#sidebar-left ul li {
    position: relative;
    text-transform: uppercase;
    padding: 0;
    margin: 0;
    overflow: hidden;
    display: block;
    height: 48px;
}

.list-header {
    border-top: 1px solid #eef0eb !important;
    border-bottom: 1px solid #c6c8c2 !important;
    height: 15px !important;
    padding: 7px 10px 5px !important;
    background: #c4c7c2;
    color: #fbfcfb;
    font-size: 14px;
}

#sidebar-left ul li a {
    width: 270px;
}

#sidebar-left ul li a {
    height: 20px;
    display: inline-block;
    border-top: 1px solid #eef0eb;
    border-bottom: 1px solid #c6c8c2;
    text-decoration: none;
    font-size: 20px;
    padding: 13px 10px;
    color: #464848;
    text-shadow: #eef0ea 1px 1px 0;
    outline: 0;
}

#sidebar-left ul li a:hover {
    border-top: 1px solid #4c4e4c;
    border-bottom: 1px solid #464848;
    text-decoration: none;
    color: #fbfcfb;
    text-shadow: #2d2e2e 1px 1px 0;
    background: #464848;
}

#sidebar-left ul li span {
    position: absolute;
    right: 10px;
    background: #ffffff;
    padding: 4px 0;
    -webkit-border-radius: 7px;
    -moz-border-radius: 7px;
    border-radius: 7px;
    font-size: 15px;
    color: #2cbcf5;
    height: 15px;
    min-width: 24px;
    text-align: center;
    z-index: 2;
    top: 0;
    font-family: 'HelveticaNeueBoldCond';
    margin: 12px 0;
    -webkit-box-shadow: 0px 1px 0px 0px #cbcec8;
    -moz-box-shadow: 0px 1px 0px 0px #cbcec8;
    box-shadow: 0px 1px 0px 0px #cbcec8; 
}

#sidebar-left ul li span:hover {
    -webkit-box-shadow: 0px 1px 0px 0px #252525;
    -moz-box-shadow: 0px 1px 0px 0px #252525;
    box-shadow: 0px 1px 0px 0px #252525;    
}
  • 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-27T03:28:21+00:00Added an answer on May 27, 2026 at 3:28 am

    Is there a reason you can’t activate the hover on the parent list items, rather than the anchor tag? If that doesn’t work, you can use the .siblings() function to select all sibling DOM elements of the span. Try something like this:

    $("ul#sidebar-categories li span").hover(function() {
        $(this).siblings().css({ 
            backgroundColor: "464848" // a tag hover bg color
        });
    }, function() {
        $(this).siblings().css({ 
            backgroundColor: "daddd7" // a tag normal bg color
        });
    }); 
    

    This will select any immediate siblings and change their background color. If you need to further filter the elements, you can pass a CSS selector to the .siblings() function.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.