获取我用jQuery悬停的元素的ID? [英] Get ID of the element I hover over with jQuery?

查看:74
本文介绍了获取我用jQuery悬停的元素的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆看起来像这样的元素:

I have a bunch of elements that look like this:

<span class='tags' id='html'>html</span>
<span class='tags' id='php'>php</span>
<span class='tags' id='sql'>sql</span>

我将如何获得悬停的那个的ID的名称,因此我可以输出类似您正在悬停在 html 标记上"的内容. (我想做的不是那么随意,但是我确实需要获取用户悬停在上面的标签的名称.)

How would I get the name of the id of the one I hover over, so I could output something like "You're hovering over the html tag". (What I want to do isn't that arbitrary, but I do need to get the name of the tag the user hovers over in order to do it.)

推荐答案

mouseover 应该可以技巧.

$('.tags').mouseover(function() {
   alert(this.id);
});

请注意,如果您也想知道鼠标何时离开,可以使用悬停

Note that if you want to know when the mouse leaves as well, you can use hover.

这篇关于获取我用jQuery悬停的元素的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆