Getting element position failes on select elements?
I'm trying to grab the X/Y co-ordinates of given elements on a page, and scroll to them using the window.scrollTo() method. This is working for standard text boxes (INPUT objects), but for drop down lists (SELECT objects), the JQuery .position() method isn't returning the result object:
-
var el = $("#[id$=" + elements[i][1]);
- if(el.position() && el.position().top)
{
var top = el.position().top;
var left = el.position().left;
window.scrollTo(top, left);
break;
-
}
This works just fine for text boxes, but will not work for selects/drop down boxes. I've stepped through the code and the element el is always populated correctly, so its not the get statements that is at fault.
Can anyone suggest what's wrong with the above please? If I inspect the value of el.position().top I get 'null or not an object' and el.position() returns 'undefined'.
Thanks