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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:45:12+00:00 2026-06-10T12:45:12+00:00

I wonder why when using .css() function, it overrides the pseudo class in CSS,

  • 0

I wonder why when using .css() function, it overrides the pseudo class in CSS, like :hover for example. Shouldn’t it only affect the normal condition of the element, not the :hover one ? or am i doing something incorrectly ?

Here’s an example

<!DOCTYPE html>

<html>  
  <head>
    <style>
      #test {
        background : red;
        width: 50px;
        height: 50px;
        opacity : 0.2;
      }

      #test:hover {
        opacity:1.0;
      }
    </style>

    <script type="text/javascript" src="../jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
      $(function () {
        $('#test').css('opacity', '0.5');
      });
    </script>
  </head>

  <body>
    <div id="test"></div>
  </body>
</html>

When the page loads, i get the div with only opacity = 0.5, for both normal and :hover.
Shouldn’t it be 0.5 for normal and 1.0 for :hover ?

My question is how to prevent this from happening ?

  • 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-10T12:45:13+00:00Added an answer on June 10, 2026 at 12:45 pm

    .css() applies inline styles to the selected element(s), and as per the rules of cascading styles inline styles have a higher priority than the styles in your stylesheet.

    You can make the class in the stylesheet more important than the inline style as follows:

     #test:hover {
         opacity:1.0 !important;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if it is possible to rearrange HTML table cells using only CSS.
I wonder if anyone can work this HTML, CSS, Javascript puzzle out? I'm using
I wonder if anyone tried using Kaazing for client push with Silverlight? How did
I wonder, using Eclipse's PyDev plugin , how come documentation does not always show
I wonder if I can execute some programs for different cmd's using .bat file.
I am using Googles Licensing in my apps and I wonder if the UserId
I am using Xcode 4.2 now. I wonder if there is a way to
I am using firefox addon builder (Addon kit 1.7) and I wonder to know
I wonder a case. I have a project using a database (Oracle and Mssql).
i'm using spring+tapestry for authenticate webuser. I wonder is there any technique i can

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.