开发者

position is not working when the containing element is inside table - jquery

When my containing element(div) is inside <td>, and If i use position(), It is not re开发者_JAVA百科turning the position relative to td. instead it returns position relative to <tr>.

Why this is happening? Any workaround for this?


position() returns the offset difference between the current element, and the closest offset parent.

If you want to get the position relative to the direct parent, use:

var element = $("div"); //Selector
var offset = element.offset().top - element.parent().offset().top;


You need to set the position CSS property of the <td> to relative:
In your css file:

table td { position:relative; }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜