jquerytextareawidthresizable

Textarea width auto resize


I want to auto resize the textarea width when I write inside it, with a max-width, like this code do for the input. http://jsbin.com/ahaxe it's possible?


Solution

  • DEMO : http://jsfiddle.net/buM6M/1/

    html:

    <textarea id="t1" style='min-width:100px;min-height: 100px'>
    
    </textarea>
    
     <div id="d1" style='max-width:200px;min-height:20px;display: none'>
    
    </div>
    

    ā€‹

    js code :

      $("#t1").live({
    keyup: function(e){
    
        $("#d1").text($(this).val());
        $(this).css("width", $("#d1").css("width"));
        $(this).css("height", $("#d1").css("height"));
    }
    });ā€‹
    

    Set the dimensions of the div and textarea as per your requirement .