Chrome makes textareas resizable by default. How can I attach events to the resizing events for the textareas ? Doing the naive $('textarea').resize(function(){...})
does nothing.

- 45,516
- 29
- 93
- 118
-
1You could check the width before and after a click. – Sampson Jan 19 '10 at 19:14
6 Answers
It doesn't look like you can specifically attach events to resizing a textarea. The resize event fires when the window is resized.

- 2,267
- 1
- 21
- 23
I can't test this right now, but according to this forum entry it can be disabled using:
style="resize: none;"
unlike stated in that entry, max-width
and max-height
won't cut it - thanks to @Jonathan Sampson for the info.

- 442,112
- 142
- 972
- 1,088
-
2+1 `resize:none` disables it. `max-width` and `max-height` didn't: http://jsbin.com/inane – Sampson Jan 19 '10 at 19:20
Here's a jQuery plugin written using CoffeeScript. Idea from Jonathan Sampson.
$.fn.sizeId = ->
return this.height() + "" + this.width()
$.fn.textAreaResized = (callback) ->
this.each ->
that = $ this
last = that.sizeId()
that.mousedown ->
last = that.sizeId()
that.mousemove ->
callback(that.get(0)) if last isnt that.sizeId()
You can build it to Javascript on the CoffeeScript's homepage
http://jashkenas.github.com/coffee-script/
Use the "Try CoffeeScript" button.

- 18,293
- 11
- 75
- 82
This is an old question, but someone else had the same one in IRC, so I decided to solve it here: http://jsfiddle.net/vol7ron/Z7HDn/
Everyone's right that Chrome doesn't capture the resize event and that Chrome doesn't capture the mousedown, so you need to set the init state and then handle changes through mouseup:
jQuery(document).ready(function(){
// set init (default) state
var $test = jQuery('#test');
$test.data('w', $test.outerWidth());
$test.data('h', $test.outerHeight());
$test.mouseup(function(){
var $this = jQuery(this);
if ( $this.outerWidth() != $this.data('w')
|| $this.outerHeight() != $this.data('h')
)
alert( $this.outerWidth() + ' - ' + $this.data('w') + '\n'
+ $this.outerHeight() + ' - ' + $this.data('h'));
// set new height/width
$this.data('w', $this.outerWidth());
$this.data('h', $this.outerHeight());
});
});
HTML
<textarea id="test"></textarea>

- 40,809
- 21
- 119
- 172
There is jquery-resize which once included just makes your given line work: http://benalman.com/projects/jquery-resize-plugin/

- 2,150
- 1
- 24
- 18
Similar to Epeli's answer I've tried to start on a clean solution to trigger a resize() event on mousedown: http://jsfiddle.net/cburgmer/jv5Yj/3/ However it only works with Firefox as Chrome doesn't seem to trigger mousedown on the resize handler. However it does trigger mouseup.

- 2,150
- 1
- 24
- 18