I have a bunch of elements that look like this:
These solutions still returned an empty alert for me. For me, following worked when I handled the event object passed to the hover function:
$(".input-box").hover(function(eventObj) {
alert(eventObj.target.id);
});
Source of this solution
$('.tags').hover(
function() { console.log( 'hovering on' , $(this).attr('id') ); },
function() {}
);
Second empty function is for mouse out, you'll probably want to do something on that event as well.
Use this one:-
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").hover(function(){
//if get onhover id
alert("NOW GET ON HOVER ID NAME:--"+" "+this.id);
//if get onhover class
alert("NOW GET ON HOVER CLASS NAME:--"+" "+$(this).attr('class'));
});
});
</script>
</head>
<body>
<p class="getclass" id="get_class_id" >Hover the mouse</p>
</body>
</html>
mouseover should do the trick.
$('.tags').mouseover(function() {
alert(this.id);
});
Note that if you want to know when the mouse leaves as well, you can use hover.