0

Listen guys Im here again, I have a trouble and I donk know how to search for my problmen in the web (I searched for that like "remove hover" and I didnt find what I wanted).

I have a style like this one:

.myStyle li:hover
{
     background: #9999FF;
}

and I have this in my html

<ul class="myStyle">
<li id="li1">1</li>
<li id="li2">2</li>
<li id="li3">3</li>
</ul>

and I have this script too

$('ul li').on('click', function() {
     $(this).prependTo(list.closest('ul'));
}

So now, its works perfectly, but the li moved conserves the color of the class (#9999FF) after click, and doesnt quit until I pass the mouse over there. I have tried to remove class with removeClass but it doesnt work, please help me.

Any ideas for my problem?

Thank for u time!

3 Answers3

0

No, you can't, but you can attach styles not to tags but to classes and on hover event you can delete/add the class.

In jQuery hover is a combination of mouseenter and mouseleave events, so you can bind a handler for a hover start:

CSS:

.hoverable {
    /* your styles */
}
.hoverable:hover {
    /* your styles you want not to attach */
}

HTML:

<ul>
    <li class="hoverable">Hover not makes effect</li>
    <li>Hover makes effect</li>
</ul>

Javascript:

var className = 'hoverable'; 
$('ul li').on('mouseenter', function(e) {
    $(this).removeClass(className); 
}).on('mouseleave', function(e) {
    $(this).addClass(className);
});

(jsfiddle is here)

So it's possibly can prevent the unwanted effect.

And, of course, instead of this you can just redefine styles and set all the unwanted styles to 'inherit' etc., it will be the better solution.

Also, there is a similar question on StackOverfow: Can I disable a CSS :hover effect via JavaScript?

Community
  • 1
  • 1
devlato
  • 127
  • 4
0

Its not :hover then, If its retaining the color after clicking, its :active,

Try resetting the :active color,

.myStyle li:active{
  color:#<put-previous-color-hex-value-here>;
}
Nagendra Rao
  • 7,016
  • 5
  • 54
  • 92
0

this seems to work: for testing sake, I changed "list" to ".myStyle". Change per your needs.

http://jsfiddle.net/EhBD4/

$(document).ready(function(){
  $('ul li').on('click', function() {
     $(this).prependTo($('.myStyle').closest('ul'));
     $(this).css("background-color", "transparent");
  })
})
james emanon
  • 11,185
  • 11
  • 56
  • 97