Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

element id on mouse over

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?

like image 602
kawade Avatar asked May 31 '11 10:05

kawade


People also ask

How do I find my mouseover ID?

mouseover should do the trick. $('. tags'). mouseover(function() { alert(this.id); });

How do you check if the mouse is over an element?

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.

How do I grab an element by ID?

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.


1 Answers

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);" />
like image 102
Anand Thangappan Avatar answered Oct 01 '22 05:10

Anand Thangappan