views:

411

answers:

3

Hello.

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>
+1  A: 
      $("#mouse").text("Mouse - Top: " + eleoffset.top + " - Left: " + eleoffset.left + " id " + $(this).id);

I think

Jeremy French
+3  A: 

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
That works :) Thanks!
Cudos
Smart. Last time I checked MDC they have some methods that can identify the objects based on the position on the window.
rymn
A: 

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

Tom Hubbard