Jump to content



Photo

toggle one at a time? jQuery


  • Please log in to reply
2 replies to this topic

#1 ACTIONpack

ACTIONpack

    Graphic Designer

  • Tech Issues Solved: 1
  • Joined: 10-August 03
  • Location: Lawrenceville, GA
  • OS: Windows 8.1 Pro
  • Phone: Nokia Lumia 925 (T-Mobile)

Posted 09 April 2013 - 18:43

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>


#2 EddieF

EddieF

    Neowinian

  • Joined: 04-November 02
  • Location: Ohio/Michigan border
  • OS: Win 7
  • Phone: Droid Razr

Posted 10 April 2013 - 00:19

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


#3 Sandor

Sandor

    Neowinian Senior

  • Joined: 28-November 03
  • Location: Canada
  • OS: Win 8.1
  • Phone: WP8

Posted 10 April 2013 - 01:41

Just to note: that is invalid markup.

div not allowed as child of ul