Identify onmouseover element

Asked

Viewed 88 times

3

I want to identify what kind of element it is by going through an element. I’m doing the following example:

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

example: http://jsfiddle.net/e5msph9x/

1 answer

3


You have to use e.target and only after nodeName. e is the event object that has a property target where it points to the DOM element, which in turn has a property named after this type of HTML Node.

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

Also remember to always pass the object e (event) in that chain of functions you have, or use the function directly (thus).

jsFiddle: http://jsfiddle.net/e5msph9x/1/

  • Thanks @Die, is it possible instead of appearing an Alert appear a small div with css styles over the element? example: http://jsfiddle.net/e5msph9x/3/ This is then used in a graph and div are a circle.

  • @akm when you say over, you mean over or over but not over? You know you can do that with CSS too... http://answall.com/a/64939/129

  • Label this genus, http://www.d3noob.org/2013/01/adding-tooltips-to-d3js-graph.html, slightly above the circle.

  • @akm thus? -> http://jsfiddle.net/j8znfc1m/

  • 1

    Thank you @Rgio

Browser other questions tagged

You are not signed in. Login or sign up in order to post.