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

The Archive Base Latest Questions

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

I’m a new to the jQuery world and I’m having a problem that I

  • 0

I’m a new to the jQuery world and I’m having a problem that I just can’t solve. I have an unordered list with multiple li’s. I’m trying to make it so when the user clicks a row, the bg color on the row changes. And when another row is click, that row’s bg color changes and the previous on goes back to the default color. This is my code so far:

$('.allVideos ul li').hover(function(){
   $(this).css('background','#c7f1f2');
}, function(){
   $(":not($(this))").css('background','');
});

Unfortunately it isn’t working as planned. Can anyone explain to me what I am doing wrong?

Thanks

  • 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-26T02:45:55+00:00Added an answer on May 26, 2026 at 2:45 am

    You want to use the not filter, not the :not selector:

    $('li').click(function() {
        $(this).css('background-color', '#c7f1f2');
        $('li').not(this).css('background-color', '');
    });
    

    Demo: http://jsfiddle.net/ambiguous/ZUk88/

    When you say li:not($(this)) then you’re trying to select all <li> elements that aren’t <$(this)> elements and that doesn’t make sense; similarly for li:not(this).

    You could also remove the background color from all the list items and then add it to the one you want:

    $('li').click(function() {
        $('li').css('background-color', '');
        $(this).css('background-color', '#c7f1f2');
    });
    

    Demo: http://jsfiddle.net/ambiguous/L6ZNz/

    Also, your question talks about clicking but your code talks about hovering.


    If you have colors already attached to your <li> elements and you want to restore those colors when someone clicks another <li>, then you should just add and remove a CSS class to change the color. A bit of CSS:

    .hilight {
        background-color: #c7f1f2 !important;
    }
    

    and some jQuery:

    $('li').click(function() {
        $(this).siblings('.hilight').removeClass('hilight');
        $(this).addClass('hilight');
    });
    

    Demo: http://jsfiddle.net/ambiguous/ZJpNa/

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.