jquerydompositionelementname

Getting element name based on position in DOM


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>

Solution

  • 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