Identify onmouseover element

3

I want to pass on an element, identify what kind of element it is. I'm doing the following example:

window.onmouseover =  function(){ mouseOver(e)};
function mouseOver(e) {
  if (e.nodeName === "DIV"){
    alert("it's a div");
 }    
}

example: link

    
asked by anonymous 22.05.2015 / 16:53

1 answer

3

You have to use e.target and then nodeName . e is the event object that has a target property where it points to the DOM element, which in turn has a property with the name of that type of HTML node.

So it should be if (e.target.nodeName === "DIV"){

Do not forget to always pass the object e (event) to this string of functions you have, or use the function directly ( so ).

jsFiddle: link

    
22.05.2015 / 16:56