0

I want to find the name or ID of a element where I got top and left position.

I know how to use jquery to find the position of an element (Hovering over the div will trigger that position text will appear on screen):

    $(".item").hover(function () {
      var eleoffset = $(this).offset();
      $("#mouse").text("Mouse - Top: " + eleoffset.top + " - Left: " + eleoffset.left);
    });


<div class="item">This is a text block</div>
<div id="mouse">Waiting for position data...</div>
Facundo Casco
  • 10,065
  • 8
  • 42
  • 63
Cudos
  • 5,733
  • 11
  • 50
  • 77

3 Answers3

3

I'm not quote sure what you mean. But you can get the name or ID using:

 $(this).attr('id');
 $(this).attr('name');

in the hover handler

Pim Jager
  • 31,965
  • 17
  • 72
  • 98
  • Smart. Last time I checked MDC they have some methods that can identify the objects based on the position on the window. – rymn May 12 '09 at 16:07
1
      $("#mouse").text("Mouse - Top: " + eleoffset.top + " - Left: " + eleoffset.left + " id " + $(this).id);

I think

Jeremy French
  • 11,707
  • 6
  • 46
  • 71
0

this.id and this.name ought to work as well. Shouldn't need the extra JQuery call.

Tom Hubbard
  • 15,820
  • 14
  • 59
  • 86