• 0

toggle one at a time? jQuery


Question

Not really good at jQuery or javascript. I'm trying to show a hidden DIV when hover over a <li>. My only problem is that I have many DIV and don't want all to show and only want the DIV that is in <LI> to show only and not all.


<ul>
<li>
<div class="productWrap">
<h3>Time</h3>
<div class="productContent">
<img src="../images/products/list/BioCalce-AnticoPIX.jpg" alt="" title="" />
<span><img src="../images/products/list/BioCalce-Antico.png" alt="" title="" /></span>
<h4>Time</h4>
<ul>
<li>Classic Lime Paint</li>
<li>Interior / Exterior</li>
<li>Wall Paint</li>
<li>Decorative Finish</li>
</ul>
<a href="#" title="">Learn More <em>→</em><strong>→</strong></a>
</div>
</div>
</li>

<li>
<div class="productWrap">
<h3>Place</h3>
<div class="productContent">
<img src="../images/products/list/BioCalce-AnticoPIX.jpg" alt="" title="" />
<span><img src="../images/products/list/BioCalce-Antico.png" alt="" title="" /></span>
<h4>Place</h4>
<ul>
<li>Classic Lime Paint</li>
<li>Interior / Exterior</li>
<li>Wall Paint</li>
<li>Decorative Finish</li>
</ul>
<a href="#" title="">Learn More <em>→</em><strong>→</strong></a>
</div>
</div>
</li>

<li>
<div class="productWrap shadow horizontal">
<h3>People</h3>
<div class="productContent">
<img src="../images/products/list/BioCalce-AnticoPIX.jpg" alt="" title="" />
<span><img src="../images/products/list/BioCalce-Antico.png" alt="" title="" /></span>
<h4>People</h4>
<ul>
<li>Classic Lime Paint</li>
<li>Interior / Exterior</li>
<li>Wall Paint</li>
<li>Decorative Finish</li>
</ul>
<a href="#" title="">Learn More <em>→</em><strong>→</strong></a>
</div>
</div>
</li>
</ul>

<script type="text/javascript">

$(function() {
$('.productWrap').hover(function() {
$('.productContent').toggle(200);
});
});
[/CODE]

</script>

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hello! You'll want to use Jquery's children() or next(). Also, hover() isn't going to work well for this, because every time you move the mouse the slightest it will toggle, making it show/hide/show/hide very quick. mouseenter() and mouseout() are better suited.


$(function() {
$('.productWrap').mouseenter(function() {
$(this).children('.productContent').show();
});

$('.productWrap').mouseout(function() {
$(this).children('.productContent').hide();
});
});
[/CODE]

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.