javascript - Replace a button with another on hover not working jQuery -


i have 2 buttons, , want display 1 button displayed @ time on hover, button replaced , first button on mouseout.

i came out following piece of code on hover keeps going , forth between 2 buttons, best way ?

 $(document).ready(function() {            $('.price').on('mouseover',function() {                          $(this).css('display','none');                $(this).next('.buy').css('display','block');            });             $('.price').on('mouseout',function() {                          $(this).css('display','block');                 $(this).next('.buy').css('display','none');            });          });
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="price-div" style="      display: block;  ">                                                                        <button type="button" class="btn btn-default price" style="display: block; z-index: 9999999999999; position: absolute;"> $589.50                                                                         <!--  <button type="button" class="btn btn-default compare"><i class="fa fa-bar-chart"></i>compare</button> -->                                      </button><button type="button" class="btn btn-default buy" value="add cart" onclick="addtocart('43');" style="display: none; z-index: 999999; position: absolute;"><i class="fa fa-shopping-cart"></i> add cart</button>                                  </div>
$589.50 compare --> add cart

the reason why keeps on showing/hiding time because .buy shown, mouseout gets triggered, put mouseout on .buy element

$('.price').on('mouseover',function() {               $(this).css('display','none');     $(this).next('.buy').css('display','block'); });  $('.buy').on('mouseout',function() {               $(this).prev('.price').css('display','block');     $(this).css('display','none'); }); 

demo


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -