Designation behind the text box

I am using the following sample to display text in the background of a textbox. It works great. http://attardi.org/labels/

Problem:

I want to enlarge the textbox. The drawer appears to be expanded, but when the actual size is entered, it does not expand. I want to type text up to 600px.

Gita.

+2


a source to share


1 answer


$(".input :input").keypress(function(){
    var o = $(this); 
    var s = $("<span></span>").html(o.val()).addClass('placeholder').css('left', '-9999px'); 
    if (o.outerWidth() < 600) {
        o.parent().append(s); 
        if (s.outerWidth() > o.outerWidth()){
            o.css("width", s.outerWidth()); 
        }
        $("span.placeholder").remove();
    }
});

      



I've tested this and it seems to work pretty well. not bad for 7 minutes of code / test / write.

+1


a source







All Articles