Hide & show multiple links on a page using jquery -


i working on product shortlist feature. have grid view each product & have provided shortlist link each of grid cell. want hide these links in each cell on page load & show specific link within cell when user hovers on particular cell , again hide link when user moves cursor out of cell. cell nothing div.

the shortlist link within div having class product-grid-item.this div nothing grid cell on want hover. using toggle function able show/hide shortlist link, code generating multiple grid cells i,e div when hover on particular grid link getting displayed display links within other grids well.i want show particular link within grid on user hovers not links within other grid cells.

how can achieve using jquery? code:

<?php foreach ($products $index=>$product):?>   <div class="product-grid-item grid-cell">     <div class="shortlist" style="display: none; float:right;">     <?php       echo chtml::ajaxlink('<i class="fa fa-star"></i> shortlist',yii::app()->createurl('productshortlist/shortlistproduct'),         array('data'=>array('productid' => $product->product_id),         'datatype'=>'text',         'type'=>'get',         'success'=>'function(result)                     {                       if(result == "success")                       {                         alert("product added shortlist successfully.");                         $("#shortlistedproduct").prop("disabled",true);                       }                       else                         $("#shortlist_product_error").html(result);                       }'),         array('id'=>'shortlistedproduct'.$index)       );     ?>     </div>   </div> <?php endforeach;?> 

output:

 <a id="shortlistedproduct0" href="#"><i class="fa fa-star"></i> shortlist</a>   <a id="shortlistedproduct1" href="#"><i class="fa fa-star"></i> shortlist</a> 

suggested not working script:

<script>     $(".product-grid-item").hover(function()     {         $(".shortlist").toggle();     }    ); </script> 

now information available us, can answer question

$(function () {      $(".product-grid-item").hover(function () {          $(this).find(".shortlist").toggle();      });  });
.shortlist {display: none; float:right;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <div class="product-grid-item grid-cell">hover on me      <div class="shortlist">          <a id="shortlistedproduct0" href="#"><i class="fa fa-star"></i> shortlist</a>          <a id="shortlistedproduct1" href="#"><i class="fa fa-star"></i> shortlist</a>      </div>  </div>  <div class="product-grid-item grid-cell">hover on me      <div class="shortlist">          <a id="shortlistedproduct0" href="#"><i class="fa fa-star"></i> shortlist</a>          <a id="shortlistedproduct1" href="#"><i class="fa fa-star"></i> shortlist</a>      </div>  </div>


Comments

Popular posts from this blog

java - JavaScript + Thymeleaf - select onchange -

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -