jquery toggle on hover for multiple divs
Posted
by
Oterox
on Stack Overflow
See other posts from Stack Overflow
or by Oterox
Published on 2011-11-16T17:49:09Z
Indexed on
2011/11/16
17:50 UTC
Read the original article
Hit count: 306
I have some divs with identical structure and i want to toggle when the mouse hovers the div so a hides and b shows:
<ul class="tweets">
<li>
<div class="a">
<p>show a</p>
</div>
<div class="b">
<p>show b</p>
</div>
</li>
<li>
<div class="a">
<p>show a</p>
</div>
<div class="b">
<p>show b</p>
</div>
</li>
<li>
<div class="a">
<p>show a</p>
</div>
<div class="b">
<p>show b</p>
</div>
</li>
</ul>
This is the jquery i'm using:
$(document).ready(function(){
var tweet = $("ul.tweets .a");
tweet.hover(function(){
$('.a').toggle();
$('.b').toggle();
});
});
But this toggles ALL the divs and i only need to toggle one.I should use $(this) but i don't know how.How could i make this work?
The fiddle is here
© Stack Overflow or respective owner