javascript - 当鼠标悬停在 div 上时获取该 div 的信息

标签 javascript jquery html

我希望能够将鼠标悬停在 <div> 上并使用 JavaScript 获取信息(例如 id )并将其存储在变量中。

实现这一目标的最有效方法是什么?

最佳答案

这将为您做这件事:

$('div').mouseover(function(){
   var content = $(this).html();
   var id = $(this).attr('id');
   alert('the element\'s ID is: '+id+'and content is: '+content);
});

关于javascript - 当鼠标悬停在 div 上时获取该 div 的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6823448/

相关文章:

javascript - 在没有数据库的情况下实现聊天应用程序

jquery - 输入框值未定义

javascript - 如何向 append 添加淡入淡出?

jquery - CoffeeScript:选中复选框后 LI 上的 Line-Through

HTML Viber 链接到特定号码

javascript - jQuery 3.0 removeAttr 与 prop

javascript - 根据地址获取经纬度

javascript - 如何在 gulp 的嵌套目录中 bundle 多个文件?

javascript - 我应该使用哪些函数来进行 url 安全搜索重定向

javascript - 在小间隔内通过 javascript 更新 css 时卡住轨道动画