help with focusing a dynamically created input
<p>my code is this. on <a href="http://jsfiddle.net/KH7pZ/1/" rel="nofollow">jsfiddle</a>.</p>

<pre><code>var inp = $('&lt;input&gt;').attr({'class':'txtEdit txt', 
    'type':'text'})
    .val($(this).html()).blur(function (){
        if($(this).val().length != ''){
            $(txt).replaceWith($(editable)
                .html($(this).val()));
        }
        else{ alert("Cannot contain empty value!")}
    }).keydown(function (e){
            if(e.keyCode == 13 || e.keyCode == 9){
                e.preventDefault();
                $(this).trigger('blur');
            }
    }).appendTo($(txt));
</code></pre>

<p>I am creating an input element with lots of events and adding to div. Now i want to focus it as it is appended to DOM. but focus does not seem to be working.</p>

<p>Here's the total code.</p>

<pre><code>&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;My jQuery plugin&lt;/title&gt;
        &lt;script src="jquery.js"&gt;&lt;/script&gt;
        &lt;script&gt;
            $(function ()
            {
                    $('.editable').txtEdit();
            });

            (function($){
                $.fn.txtEdit = function() {
                    var editable = $(this);

                    $(editable).live('click', 
                        function ()
                        {
                            var txt = $('&lt;div&gt;').attr('class', 'txtEdit div');
                            var inp = $('&lt;input&gt;').attr({'class':'txtEdit txt', 
                                            'type':'text'})
                                        .val($(this).html()).blur(function (){
                                                if($(this).val().length != ''){
                                                    $(txt).replaceWith($(editable)
                                                        .html($(this).val()));
                                                }
                                                else{ alert("Cannot contain empty value!")}
                                            }).keydown(function (e){
                                                    if(e.keyCode == 13 || e.keyCode == 9){
                                                        e.preventDefault();
                                                        $(this).trigger('blur');
                                                    }
                                            }).appendTo($(txt));
                            $(this).replaceWith(txt);                           
                        }
                    );
                };
            })(jQuery);
        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div class="editable"&gt;this is editable div&lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Anyone any ideas??</p>

<p>Regards,</p>
