2016-06-22 27 views
0

我曾嘗試:如何獲得JavaScript中的CSS字體大小?

document.getElementById("foo").style.fontSize 

但是不返回任何內容。我的CSS是在同一個文檔中定義的,而不是單獨的樣式表。 我也試過這個:

var el = document.getElementById("content"); 
var style = window.getComputedStyle(el, null).getPropertyValue("font-size"); 
var fontSize = parseFloat(style); 
el.style.fontSize = (fontSize + 1) + "px"; 

但這不起作用。

這是有問題的HTML:

<p contenteditable="true" id="content">Write here. Seriously, try it.</p> 

這是CSS

#content { 
    line-height: 30px; 
    margin-top: 22px; 
    min-height: 90%; 
    display: block; 
    padding: 0 20px 0 20px; 
    font-size:15px; 
} 

回答