开发者

How to add class on hovering element in MooTools?

I am using MooTools 1.12

How to ad a class to an a element on hover?

e.g.

I have this

<a href="example.html">Some text</a>
<a href="example.html">Some text</a>
<a href="example.html">Some text</a>
<a href="example.html">Some text开发者_Python百科</a>

anf when hovering overr a link I want this:

<a href="example.html">Some text</a>
<a href="example.html">Some text</a>
<a class="hover" href="example.html">Some text</a> <!-- I am over this link -->
<a href="example.html">Some text</a>

Thanks in advance


Simply define an event which adds or remove the class on mouseenter and mouseleave.

$$('a').addEvents({
  'mouseenter': function() { $(this).addClass('hover'); },
  'mouseleave': function() { $(this).removeClass('hover'); }
});

However, if you are using this to change CSS properties on link, you are better off using the :hover pseudo-class in CSS. Using the pseudo-class will enable your changes to work on browsers without Javascript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜