user1929135
user1929135

Reputation: 31

jquery.addClass() is not working on adding the already existing attribute with different value

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.

Upvotes: 1

Views: 255

Answers (2)

NullPoiиteя
NullPoiиteя

Reputation: 57322

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;}​

Specifics on CSS Specificity

Upvotes: 3

Manish Nagar
Manish Nagar

Reputation: 1046

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");

Upvotes: 0

Related Questions