Not including whitespace when detecting text width with `<span>` trick
<p>I have implemented a jQuery pluggin to correct the width of <code>&lt;input/&gt;</code> elements depending on how much text they have, as shown:</p>

<pre><code>$.fn.correctWidth = function () {
    var tempSpan = $('&lt;span&gt;')
        .html(this.val())
        .css('font-size', this.css('font-size'))
       .insertBefore(this);
    this.width(tempSpan.width());
    tempSpan.remove();
    return this;
};
</code></pre>

<p>The problem is that, sometimes, the <code>&lt;span&gt;</code> element's width is much larger than the actual text width.</p>

<p>It seems that this occasional problem is because the detected width includes the whitespace between the end of the text and the end of the line.</p>

<p>How can I make sure that the whitespace is not included? Is there an alternative approach?</p>
