tags:

views:

257

answers:

1

I want to bind handlers for mouseenter and mouseleave to a set of elements grabbed using the jQuery selector. The function needs to act on the children of the elements.

Here is my code:

$(document).ready(function(){
 $(".topnav-link").bind("mouseenter mouseleave", function() {
  $(this).children(".topnav").toggle();
 });
});

and in the body of the html:

<ul id="nav">
 <li>
  <a class="topnav-link" href="some-url">
   <img class="topnav" src="nav-about-us.png" />
   <img class="topnav hidden" src="/images/site/nav-about-us-on.png" />
  </a>
 </li>
 <li>
  <a class="topnav-link" href="some-url'}">
   <img class="topnav" src="nav-products.png" />
   <img class="topnav hidden" src="/images/site/nav-products-on.png" />
  </a>
 </li>
 <li>
  <a class="topnav-link" href="some-url">
   <img class="topnav" src="nav-contact.png" />
   <img class="topnav hidden" src="/images/site/nav-contact-on.png" />
  </a>
 </li>
</ul>

This actually works fine on Mac/Win/FF/Safari, but on IE6 and IE8, only the first element grabbed by the $(".topnav-link") selector displays the desired behavior.

Thanks for any help as to what I'm missing!

+1  A: 

You should use CSS to achieve the desired roll-over effects.

Please read CSS Technique: Fast Rollovers Without Preload for more information.

Aware of that technique, but...The design requirement was for clickable nav items in a non-web font (so must be image or SIFR), transparent against a variable background, that changed on hover, all compatible with IE6.The CSS technique you mention is an obvious choice for simpler scenarios where you would have text in the A tag. In my case, the text had to be part of the image, so using the CSS technique would leave the A tag empty.Thanks for mentioning it, though. It may be helpful to others who come across this thread looking for a clean, simple hover effect.
akc