hover - jQuery - How to apply addClass to only current instance? -


i have code appearing hundreds of times on page:

<div class="container"> <div class="containerbutton"></div> <div class="containercontent">content</div> </div>  <div class="container"> <div class="containerbutton"></div> <div class="containercontent">content</div> </div>  <div class="container"> <div class="containerbutton"></div> <div class="containercontent">content</div> </div> 

i'm trying achieve this: whenever "containerbutton" hovered, want "containercontent" div under display , have "displayclass" class applied it. right now, anytime hover on "containerbutton" div, "containercontent" divs on page display. how can target hovered button?

here script i'm working with:

<script> jquery(document).ready(function() {  $(".container .containerbutton").hover(function () {     $(".containercontent").addclass('displayclass');     }, function(){     $(".containercontent").removeclass('displayclass'); });  }); </script> 

you have use this reference current hovered element

jquery(document).ready(function() {    $(".container .containerbutton").hover(function () {      $(this).next().addclass('displayclass');      }, function(){      $(this).next().removeclass('displayclass');  });    });
.displayclass{    display : none;    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  <div class="container">  <div class="containerbutton">1</div>  <div class="containercontent">content</div>  </div>    <div class="container">  <div class="containerbutton">2</div>  <div class="containercontent">content</div>  </div>    <div class="container">  <div class="containerbutton">3</div>  <div class="containercontent">content</div>  </div>


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo