javascript - How to check really width with "auto" value on css -
i have loop:
var takediv = document.getelementbyid('eye'); for(var i=0; i<kategoria.length; i++){ takediv.innerhtml +=^ '<img alt="'+(kategoria.length-i)+'" '+ 'onclick="changef(this.alt)" '+ 'src="mobile/img/pic/'+loc+"/mini/"+kategoria[kategoria.length-i-1][0]+'" '+ 'style="cursor: pointer;"/>'; }
all images having css:
height: 80px; width: auto;
and after loop need give div css
document.getelementbyid('eye').style.width
which sum of inner img widhts
it first post here sorry mistakes. please help, , thanks!
you can use several approaches, example getboundingclientrect()
returns absolute values position , width/height:
var width = document.getelementbyid('eye').getboundingclientrect().width;
just note not include border or padding, inner box.
then there getcomputedstyle()
- return string suffixed "px" need parse using parseint()
:
var width = parseint(getcomputedstyle(document .getelementbyid('eye')) .getpropertyvalue("width"), 10);
both returns size in pixels.
and in @rudi's answer, there offsetwidth
, , clientwidth
. won't include margin.
Comments
Post a Comment