Home:ALL Converter>HTML textarea resize event

HTML textarea resize event

Ask Time:2019-11-22T12:40:27         Author:Jeroen De Dauw

Json Formatter

I'm looking for a way to run some JS when a textarea gets resized.

After an hour of searching and fiddling I have something that kinda works, but it is not good enough.

titleTextArea.mouseup(function() {
    popup.update(); titleTextArea.focus();
});

The problem with the above code is that it also runs when clicking in the textarea. The code I am running causes the textarea to get re-rendered, which should not happen while someone is working in it, as it messes with the focus.

I've tried using jQuery resizable as per this SO post. For some reason the resize event does not fire. And really I'd prefer not needing to pull in jQuery UI for this.

Is there a way to run code on textbox resize (only on completion of resize is fine) that does not get triggered by a bunch of different actions as well?

(PS: why is there no vanilla event for this?!)

Author:Jeroen De Dauw,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58987626/html-textarea-resize-event
Prawin soni :

A simple solution can be just adding a check for width/height, not a perfect solution though:\n\n\r\n\r\nvar ta = document.getElementById(\"text-area\");\r\nvar width = ta.clientWidth, height = ta.clientHeight\r\ndocument.getElementById(\"text-area\").addEventListener(\"mouseup\", function(){\r\n if(ta.clientWidth != width || ta.clientHeight != height){\r\n //do Something\r\n console.log('resized');\r\n }\r\n width = ta.clientWidth;\r\n height = ta.clientHeight;\r\n});\r\n<textarea id=\"text-area\" rows=\"4\" cols=\"50\"></textarea>",
2019-11-22T07:36:07
yy