0

I've searched a lot for this on google, but without luck...

Basically I need some js, that can find the id/class of the element, that I'm hovering (So I can use "this"-property).

Because I have a lot of divs (Some have to be auto generated, with random names [Or maybe not, if I can use the "this"-property]) on my page, and I don't want to type in all there names (Such as I have to do in _hittest, with just gives me a true/false value)

Hope you guys can help me :D I've really search for this, for a loooongtime

*EDIT: Not a mouse hover, that I'm looking for, but when hover a div with another div

Mobilpadde
  • 1,871
  • 3
  • 22
  • 29
  • So to clarify, you're looking for something akin to collision dectection for the bounding boxes of dom elements? Dragging an element into/over another one? in that case, I think this thread my help : http://stackoverflow.com/questions/773717/please-recommend-a-jquery-plugin-that-handles-collision-detection-for-draggable-e – Damp Aug 18 '11 at 20:59
  • No, not draggable, just if a div is overlabbing another div (I can control the div, by using arrowkeys) – Mobilpadde Aug 18 '11 at 21:02
  • if you can control it with arrow keys, it is draggable (not with the mouse but with the keyboard, which is the same effect). You could possible iterate through all the DOM elements to find if their bounding boxes intersect with the moved DIV and return an array of all elements that match (so no need for id/class), I suggest you look into the jquery plugins listed in the thread I mentioned for guidance as this seems to be on the track of what you want to accomplish – Damp Aug 19 '11 at 13:41

4 Answers4

0

Just did some calculating with offset

Mobilpadde
  • 1,871
  • 3
  • 22
  • 29
0

Something like this? It will look for all the elements on the page which have id or name attribute and attach a hover event handler.

$("*[id], *[name]").hover(function(){
       alert(this.id || this.name);
});
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124
0

You could do this, although it's bad practice to select all the divs:

$('div').mouseover(function(){
    console.log(this); 
});
Jason Kaczmarsky
  • 1,666
  • 1
  • 17
  • 30
0

Put in a convenient textarea to copy from:

<textarea id="A"></textarea>

JS:

$('div').mouseover(function() {
    $('#A').html($('#A').html() + "\nID: " + $(this).attr('id') + " CLS:" + $(this).attr('class') + " Name:" + $(this).attr('name') )
})
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176