Thursday, April 21, 2011

How to determine a 'line-height' using Javascript (jQuery)?

Well, encountered the need of a line-height coding a plugin, so, can you give an advice, please? Thanks)

From stackoverflow
  • $('selector').css('line-height');
    Christopher Done : Remember to mark the answer as correct when it is correct! =)
    Veton : Wrong. In opera it returns 'normal'.
  • $('selector').css('line-height');

    Returns line height as a decimal value in pixels, with unit, e.g. "22.5px"

    Care should be taken with this solution, as different browsers will report different results. I have found that you cannot use unitless measures with line-height (eg 2.2) in your CSS, as IE6 will report an incorrect result (eg 2px instead of, eg 36px). So I recommend using unit-based line-heights with this measure.


Post a Comment