I'm using JavaScript to get the element's id on mouse over. But I am not getting it. As per my code it is showing null.
My code is:
function getid() {
var e = document.getElementById(this);
alert(e);
}
and I am calling the function on:
<input
style="margin: 8px 4px 4px 4px; width:142px; height:117px;"
type="image"
id="img"
src="images2.jpg"
onmouseover="getid();"
onmouseout="outmouse();"
/>
How can I get the elements id on mouse over?
mouseover should do the trick. $('. tags'). mouseover(function() { alert(this.id); });
You can simply use the CSS :hover pseudo-class selector in combination with the jQuery mousemove() to check whether the mouse is over an element or not in jQuery.
getElementById() The Document method getElementById() returns an Element object representing the element whose id property matches the specified string. Since element IDs are required to be unique if specified, they're a useful way to get access to a specific element quickly.
check this
function getid(obj) {
alert(obj.id);
}
<input style="margin: 8px 4px 4px; width:142px; height:117px;" type="image" id="img" src="images2.jpg" onmouseover="getid(this);" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With