Ruben
Ruben

Reputation: 89

Mootools getPosition() gives wrong position

I have a strange problem with determining the position of elements with help of the Mootools getPosition() function. The following is the case:

I have a form, which has two tables (I know this is semantically not right, however I have to work with it):

<form>
    <table>
        <!-- rows, columns and finally inputs, selects and teaxtarea here -->
    </table>
    <table>
        <!-- rows, columns and finally inputs, selects and teaxtarea here -->
    </table>
</form>

This where Javascript with Mootools comes into play. I have a small script that displays the error of a specific form field when this field is in focus, a tooltip idea. The position of this tooltip or errortip in this case is determined in with getPosition(). This work perfectly on the first table, however when focusing on an element in the second table it is just like the height of the first table is ignored.

Here a jsfiddle link: http://jsfiddle.net/Y4BVc/6/

Upvotes: 1

Views: 1619

Answers (1)

MMM
MMM

Reputation: 7310

getPosition(relative) will return the position relative to relative.

Just simply change:

var pos = el.getPosition(el.getOffsetParent().getOffsetParent());

to

var pos = el.getPosition();

This will thing its position relative to the document.

Upvotes: 3

Related Questions