javascript - object.style.fontSize not retrieving value -


i moved css styling on div tag inline styling external stylesheet. css tag follows:

#ntext{ position:absolute;  top:204px;  left:100px;  width:197px;  height:45px;  text-align:center;  font-size:24px;  white-space:nowrap;  color:#ffffff;  font-family:times new roman, times, baskerville, georgia, serif} 

i have javascript function meant reduce font size of div follows:

function rdtext() {var txt = document.getelementbyid("ntext"); var fstring = txt.style.fontsize; var fnum = parseint(fstring); fnum -=1 ; txt.style.fontsize= fnum+"px"} 

this function worked before moved styling not. tracked problem down .style.fontsize not receiving value of font size attribute didn't return correct value ("24px") when tested alert(). css appears attached because functions change other parts color work fine. able adjust font size manually in style sheet.

i'm making stupid mistake here life of me don't know is.

this job getcomputedstyle()

function rdtext(){   var txt = document.getelementbyid("ntext");   var fnum = parseint(getcomputedstyle(txt)['font-size']);   fnum -=1 ;   txt.style.fontsize= fnum+"px" } 

if need support old ie: http://www.quirksmode.org/dom/getstyles.html


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -