Instead of .style
property, you need to getComputedStyle()
of your p
element
var elementStyle = window.getComputedStyle(*DOM element*);
After that you can simply use elementStyle.getPropertyValue(*style-property*)
prop.
Btw. you can check computed style under your console (firefox screenshot):

See working example:
var myp = document.getElementById('myp');
var heightLabel = document.getElementById('heightLabel');
var mypStyle = window.getComputedStyle(myp);
heightLabel.innerHTML = mypStyle.getPropertyValue('line-height') + " is the line height.";
// console.log(mypStyle.getPropertyValue('line-height')); // output 20px
// console.log(typeof mypStyle.getPropertyValue('line-height')); // string
// Using parseFloat we convert string into value
// Examples:
// parseFloat('20px') // 20, typeof number
// parseFloat('22.5rem') // 22.5 typeof number
// If you are sure, your string will always contain intenger value use parseInt() instead
// DOES not work cross-browser
// Chrome return line-height normal, firefox '20px'
// var getNumberValue = parseFloat(mypStyle.getPropertyValue('line-height')); // 20, typeof string
console.log(getLineHeight(myp));
// https://stackoverflow.com/questions/4392868/javascript-find-divs-line-height-not-css-property-but-actual-line-height?noredirect=1&lq=1
function getLineHeight(element){
var temp = document.createElement(element.nodeName);
temp.setAttribute("style","margin:0px;padding:0px;font-family:"+element.style.fontFamily+";font-size:"+element.style.fontSize);
temp.innerHTML = "test";
temp = element.parentNode.appendChild(temp);
var ret = temp.clientHeight;
temp.parentNode.removeChild(temp);
return ret;
}
<div>
<p id=myp>People assume I'm a boiler ready to explode, <br>but I actually have very low blood pressure, <br>which is shocking to people.</p>
</div>
<h3 id="heightLabel"></h3>