Need a jquery script that shows alert when you mouseover on each list a tag -


if list tag href mens display alert('men') , on. if womem display alert('women')

 $(document).ready(function () {     $(".mainitem").mouseover(function () {         var = $('li a').each(             function () {                 if ($(a).attr('href') == "/pages/men") {                     alert('men');                 }                 else if ($(a).attr('href') == "/pages/women") {                     alert('women');                 }                 else if ($(a).attr('href') == "/pages/services") {                     alert('services');                 }             });      });  }); 

use $(this), not $(a)...

$(document).ready(function () {             $('li a').on("mouseenter",                  function () {                     if ($(this).attr('href') == "/pages/men") {                         alert('men');                     }                     else if ($(this).attr('href') == "/pages/women") {                         alert('women');                     }                     else if ($(this).attr('href') == "/pages/services") {                         alert('services');                     }                 });      }); 

and dont need var = a, if dont use afterwards.

from comment: should attach event on a self...

another thing! practice cache $(this) better performance:

var $this = $(this); 

and then:

if ($this.attr('href') == "/pages/men") {     alert('men'); } 

and on...


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -