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 ?
.css()edits the elements inline styles, thus, overriding your pre-defined CSS.