Select all text on focus using jQuery
<p>I have a little jQuery function that is meant to automatically select text in an asp.net text box when it gets focus. However, the text in the text box gets selected, but immediately then deselects.</p>

<p>The code works if i bind to the focus event with .focus(function()) but I am adding the text boxes to the page dynamically which is why I think I need to use the live event.</p>

<p>Can anyone see a problem? The text boxes in question are in Item templates of two gridviews inside a multiview if that makes a difference?</p>

<p>Code:</p>

<pre><code>&lt;script type="text/javascript"&gt;

    //Select all text in Cost Rate Text Boxes when they have focus
    $(document).ready(function () {
        $(".CostRateTextBox").live('focus', function () {
            $(this).select();
        });

    });

&lt;/script&gt;
</code></pre>

<p><img src="http://i.stack.imgur.com/gzDiz.png" alt="enter image description here"></p>

<p>Edit:</p>

<pre><code>&lt;script type="text/javascript"&gt;

    //Select all text in Cost Rate Text Boxes when they have focus
    $(document).ready(function () {
        $(".CostRateTextBox").live('focus', function () {
            $(this).select();
            preventDefault();
        });

    });

&lt;/script&gt;
</code></pre>
