Bug Tracker

Opened 17 years ago

Closed 16 years ago

Last modified 11 years ago

#74 closed enhancement (fixed)

css('top') and css('left')

Reported by: [email protected] Owned by:
Priority: minor Milestone:
Component: core Version:
Keywords: css, top, left Cc:
Blocked by: Blocking:


It would be really cool for jquery to make an exception for css('top') and css('left') where if they are not set or if they are set to auto it will find them. I've been forced to extend jquery to get the desirec effect:

get the top position of an element $.fn.postop = function() {

var postop = 0; var obj = this.get(0); while(obj && obj != null) {

postop += obj.offsetTop; - obj.scrollTop obj = obj.offsetParent;

} return postop;


get the left position of an element $.fn.posleft = function() {

var posleft = 0; var obj = this.get(0); if(obj) {

posleft = obj.offsetLeft; while((obj = obj.offsetParent) != null) {

posleft += obj.offsetLeft;


} return posleft;


Change History (4)

comment:1 Changed 17 years ago by dave.methvin

I agree it would be useful to have a .top() and .left() that did the heroics needed to get reasonable values, but I don't want it to be at the expense of .css(). Otherwise it's impossible to see what values the CSS really had there. Already with $().css('width', '20em') you do not get '20em' back from .css('width').

comment:2 Changed 17 years ago by john

Milestone: 1.0
Version: 1.0b1

comment:3 Changed 16 years ago by brandon

Resolution: fixed
Status: newclosed

This is now available through the $().offset() method in dimensions.js. Modifying the $().css() method would result in unexpected behavior for those expecting the actual css value of top or left.

comment:4 Changed 11 years ago by anonymous


Note: See TracTickets for help on using tickets.