Get true content size

筅森魡賤 提交于 2019-12-06 06:10:27

You may create a range of the element's text-contents and use the properties of the range:

/**
  * @param object o DOMElement
  * @return int|null boundingHeight
  **/
function fx(o)
{
  if(document.createRange)
  {
    var r = document.createRange();
        r.selectNodeContents(o);
    return r.getBoundingClientRect().height;
  }
  else
  {
    var r = document.body.createTextRange();
        r.moveToElementText(o)
    return r.boundingHeight;
  }
  return null;
}

http://jsfiddle.net/doktormolle/wArMN/

If you are referring the font-size, you can check it with this:

$('div').click(function()
{
    alert($(this).css('font-size'));
});

Demo.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!