javascript - How to Calculate OffsetLeft from parent excluding parent's left padding & border -


is there easy way calculate offsetleft direct parent, excluding padding , border width of parent?

when this, returned value includes left border , padding width of parent.

child.offsetleft - parent.offsetleft 

jsfiddle

i know can subtract left border+padding width of parent, means must use getcomputedstyle retrieve values, strip 'px' , convert int, subtract... isn't there better?

look commented. wrote offsetleft property of each element doesnt not include border of offsetparent 2 exceptions wrote, here offsetparent document.body each element. calculation goes

child.offsetleft - parent.offsetleft - parent.clientleft -     parseint(getcomputedstyle(parent).paddingleft) 

because difference of 2 offsetleft properties including parent border.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -