I have a div with style="display:none". On mouse hover on a link I want to show it by adding a class with display=block but it is not working.
2 Answers
you need to use !important in class .Check this awesome answer to see how !important works
/*html*/ <div class="first" style="display:none;">sdfirst</div> <div class="second" >second</div> /*jquery*/ $(".second").mouseover(function() { $(".first").addClass("ss"); }) /*css*/ .ss{display:block !important;} Comments
use this code
<html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body><div id="main"> Mouse Over (click here for event) <div id="div1" style="display:none">hello how are you</div> </div><script> var i = 0; $('#main').mouseover(function() { $('#div1').css('display','block'); }).mouseout(function(){ $('#div1').css('display','none'); }); </script></body> </html> for add the you can use
$('#div1').addClass("className");
!important). Best is to avoid use use ofstyleentirely or use theshow()/hide()/toggle()methods. Use the developer tools from your browser to inspect the matching CSS rules and the applied rules.