开发者

Getting the left property of an LI element in jQuery?

开发者 https://www.devze.com 2023-01-09 16:44 出处:网络
I have a dynamic list of LI\'s inside of a UL. I am trying to somehow be able to \'track\' the last LI of the UL which has a class of Last.

I have a dynamic list of LI's inside of a UL.

I am trying to somehow be able to 'track' the last LI of the UL which has a class of Last.

I thought if I could test for the left property of the actual LI against some number, say -500, then I could do what I need to do.

The issue is I 开发者_StackOverflow社区can't seem to get that property.

Is this even possible or does the parent (UL in this case) override that?


If you want the left position relative to the page, you could do this:

var left = $('ul li.Last').offset().left;

Or relative to its parent, do this:

var left = $('ul li.Last').position().left;
  • http://api.jquery.com/offset/
  • http://api.jquery.com/position/

Example: http://jsfiddle.net/7Ztns/

0

精彩评论

暂无评论...
验证码 换一张
取 消