Note that there are some explanatory texts on larger screens.

plurals
  1. POGet CSS height of HTML DOM element in non-pixel unit, in my case inches
    text
    copied!<p>EDIT: sorry about the inconsistencies with width and height in my question, it applies to both though.</p> <p>EDIT 2: I still get an innaccurate value regardless of the zoom, doing this</p> <p><code>$('#selector').css('width',$('#selector').css('width'));</code> actually resizes the element.</p> <p>I have a page element measured in inches. The firefox property inspector states the correct height <code>(8.5in)</code> but using <code>$('selctor').css('width')</code> it returns it in pixels <code>("815.66666px")</code>. This is problematic for me. </p> <p>My use case is that I am toggling the size at one point in my script, and I want to be able to set it back to its default size later. In between toggling the size, and setting back to the default, the user may have zoomed the page. Due to firefox (and I think other browsers as well) less-than-perfect unit conversions, I get different round off errors based on the zoom level. For example, changing the zoom to various levels between <code>25%</code> and <code>300%</code> on my page yields the following results for the <code>css('width')</code> on the same element:</p> <pre><code> &gt;&gt;&gt; $('#templateDiv0').css('width') "815.66666px" &gt;&gt;&gt; $('#templateDiv0').css('width') "815.76666px" &gt;&gt;&gt; $('#templateDiv0').css('width') "816.33334px" &gt;&gt;&gt; $('#templateDiv0').css('width') "816.13334px" </code></pre> <p>And so when I need to reset it back to the default size later, I have no guarantee that this is the correct size. I really would like it to just return (8.5in) to me. I guess the issue is that jQuery is retrieving it in its own way, and I would want to retrieve it in the way the property inspector does, which is by looking at the style sheet directly. Is there any way to do this?</p> <p>The stylesheet for the page changes often, so hardcoding the value is not a good solution for me.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload