Q:

This object at .mouseenter() function

I'm having a simple (I hope it's simple) question. I'm using 10 divs (div1, div2...) and I want to calculate the distance between two of them. I've already clicked one, that takes the class (img.home). I have the function to calculate the distance between two objects showdistance(div1, div2), but How can I use it to calculate showdistance($('img.home').parent()[0], $(this) ) where (this) is the div, that my cursor is point at at the moment (   .mouseenter(function() {$(this).text(showdistance)});   )
Thanks in advance,
If needed, I can make a jsfiddle with the whole code, but as I believe it is a rather easy thing, that I don't know and the code is a large piece it's easier this way.
Best regards.

A:

Store your last clicked element in a variable.
Then compare the position when you enter an element.
You can apply top, left, right or bottom, if you like.
var clicked = null;

$("someSelection").click(function() {
    clicked = $(this);
});

$("someSelection").mouseenter(function() {

    // if-statement to ensure that the event won't fire if you haven't clicked one
    if(clicked !== null) {
        console.log($(this).position().top - clicked.position().top);
        console.log($(this).position().left - clicked.position().left);
    }
});

