Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: Hover to show/hide individual object

Tags:

jquery

Basically I need to hover over an anchor to display the "data-meta" div. Works just fine but when there's multiple td and divs, one hover displays all of them. My question is how can I show/hide them individually? Code snippets below.

<td>
<a href="#">Item</a>
<div class="data-meta">
    <a href="#">Edit</a> | <a href="#">Disable</a> | <a href="#">Delete</a>
</div>

 $(document).ready(function(){        
    $("td").hover(
        function () {
        $('.data-meta').show();
        },
        function () {
        $('.data-meta').hide();
    });
});
like image 371
noe ruiz Avatar asked Nov 24 '25 00:11

noe ruiz


1 Answers

Just pass a context to your selector:

$(function() {
 $('td').hover(
  function() {
   $('.data-meta', this).show();
   // Other cool stuff goes here
  },
  function () {
   $('.data-meta', this).hide();
   // Other cool stuff goes here
  }
 );
});
like image 157
Mathias Bynens Avatar answered Nov 25 '25 17:11

Mathias Bynens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!