views:

29

answers:

1

Hello

I want to attach OnMouseOver even for all the anchor tags in a page. But i if any of the anchor tags already has a OnMouseOver even i dont want to replace it. I just want to add my event handler there.

How can i achieve it through Javascript or JQuery?

+2  A: 

The default behavior is to add not replace an event, so just use .mouseover(), like this:

$(function() {
  $('a').mouseover(function() {
    //do something
    alert('My url is: ' + this.href);
  });
});

Give it a try here. Or maybe you're after .hover(), for example if you had the color plugin or jQuery UI and you wanted to animate the color:

$(function() {
  $('a').hover(function() {
    $(this).animate({ color: '#123456' });
  }, function() {
    $(this).animate({ color: '#000099' });
  });
});

You can give it a try here

Nick Craver