1

I have tried:

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

However that returns nothing. My CSS is defined in the same document and not a separate stylesheet. I have also tried this:

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

but that doesn't work.

This is the html in question:

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

And this is the css

#content {
    line-height: 30px;
    margin-top: 22px;
    min-height: 90%;
    display: block;
    padding: 0 20px 0 20px;
    font-size:15px;
}
DaniP
  • 37,813
  • 8
  • 65
  • 74

1 Answers1

3

Try passing the element to the window.getComputedStyle method

window.getComputedStyle(document.getElementById('foo')).fontSize
lostsource
  • 21,070
  • 8
  • 66
  • 88