Sign in to follow this  
Followers 0

toggle one at a time? jQuery

3 posts in this topic

Posted

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>&rarr;</em><strong>&rarr;</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>&rarr;</em><strong>&rarr;</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>&rarr;</em><strong>&rarr;</strong></a>

				    </div>

    </div>

</li>

</ul>


<script type="text/javascript">


$(function() {

  $('.productWrap').hover(function() { 

    $('.productContent').toggle(200);

  });

});

</script>

Share this post


Link to post
Share on other sites

Posted

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();

  });

});

Share this post


Link to post
Share on other sites

Posted

Just to note: that is invalid markup.

div not allowed as child of ul

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.