Update D3 text width by adding new width
<p>I have a D3 text added inside a rectangle , where the value of text field is  updated programtically. Now I need to expand the width based on the text value length  but making sure to keep the default width as min width. 
I have tried getting the new value.length and updating the d3 text width like below.</p>

<pre><code>var length = //length of the updated text value
var elm = d3.selectAll("[id=s1]");
elm.attr('width', function(d) { return  length; });
</code></pre>

<p>This works fine but when i delete the text D3 text box also shrinks all the way. I need to keep a default width and then just increase if the value is longer than that. Any idea how to do this?</p>