.resize() function for textarea
up vote
1
down vote
favorite
I want to save the height and width of the textarea
when the user change it's dimensions.
I've tried to use:
$('textarea').resize(function() {
var height = $('textarea').css('height');
var width = $('textarea').css('width');
$.post('vocabresize.php?height=' + height + '&&width=' + width, function() {});
});
But the $.post() function hasn't been called, so I changed it to:
$('textarea').resize(function() {
$('body').html('Yay it worked');
});
And when I was changing size of textarea
the 'Yay it worked' didn't appeared.
javascript jquery events jquery-events
New contributor
add a comment |
up vote
1
down vote
favorite
I want to save the height and width of the textarea
when the user change it's dimensions.
I've tried to use:
$('textarea').resize(function() {
var height = $('textarea').css('height');
var width = $('textarea').css('width');
$.post('vocabresize.php?height=' + height + '&&width=' + width, function() {});
});
But the $.post() function hasn't been called, so I changed it to:
$('textarea').resize(function() {
$('body').html('Yay it worked');
});
And when I was changing size of textarea
the 'Yay it worked' didn't appeared.
javascript jquery events jquery-events
New contributor
Sorry, I miss-copied
– Dmitry Khotinskiy
Nov 12 at 17:36
So one code smell is that you are using$.post()
without post data. You're sending data with a url query string.
– Taplar
Nov 12 at 17:38
idownvotedbecau.se/itsnotworking
– connexo
Nov 12 at 17:38
Possible duplicate of Resize event for textarea?
– Ian
Nov 12 at 17:40
You also have&&width=
which would be an invalid url string
– Taplar
Nov 12 at 17:40
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I want to save the height and width of the textarea
when the user change it's dimensions.
I've tried to use:
$('textarea').resize(function() {
var height = $('textarea').css('height');
var width = $('textarea').css('width');
$.post('vocabresize.php?height=' + height + '&&width=' + width, function() {});
});
But the $.post() function hasn't been called, so I changed it to:
$('textarea').resize(function() {
$('body').html('Yay it worked');
});
And when I was changing size of textarea
the 'Yay it worked' didn't appeared.
javascript jquery events jquery-events
New contributor
I want to save the height and width of the textarea
when the user change it's dimensions.
I've tried to use:
$('textarea').resize(function() {
var height = $('textarea').css('height');
var width = $('textarea').css('width');
$.post('vocabresize.php?height=' + height + '&&width=' + width, function() {});
});
But the $.post() function hasn't been called, so I changed it to:
$('textarea').resize(function() {
$('body').html('Yay it worked');
});
And when I was changing size of textarea
the 'Yay it worked' didn't appeared.
javascript jquery events jquery-events
javascript jquery events jquery-events
New contributor
New contributor
edited Nov 12 at 21:17
Ian
1,81631944
1,81631944
New contributor
asked Nov 12 at 17:33
Dmitry Khotinskiy
113
113
New contributor
New contributor
Sorry, I miss-copied
– Dmitry Khotinskiy
Nov 12 at 17:36
So one code smell is that you are using$.post()
without post data. You're sending data with a url query string.
– Taplar
Nov 12 at 17:38
idownvotedbecau.se/itsnotworking
– connexo
Nov 12 at 17:38
Possible duplicate of Resize event for textarea?
– Ian
Nov 12 at 17:40
You also have&&width=
which would be an invalid url string
– Taplar
Nov 12 at 17:40
add a comment |
Sorry, I miss-copied
– Dmitry Khotinskiy
Nov 12 at 17:36
So one code smell is that you are using$.post()
without post data. You're sending data with a url query string.
– Taplar
Nov 12 at 17:38
idownvotedbecau.se/itsnotworking
– connexo
Nov 12 at 17:38
Possible duplicate of Resize event for textarea?
– Ian
Nov 12 at 17:40
You also have&&width=
which would be an invalid url string
– Taplar
Nov 12 at 17:40
Sorry, I miss-copied
– Dmitry Khotinskiy
Nov 12 at 17:36
Sorry, I miss-copied
– Dmitry Khotinskiy
Nov 12 at 17:36
So one code smell is that you are using
$.post()
without post data. You're sending data with a url query string.– Taplar
Nov 12 at 17:38
So one code smell is that you are using
$.post()
without post data. You're sending data with a url query string.– Taplar
Nov 12 at 17:38
idownvotedbecau.se/itsnotworking
– connexo
Nov 12 at 17:38
idownvotedbecau.se/itsnotworking
– connexo
Nov 12 at 17:38
Possible duplicate of Resize event for textarea?
– Ian
Nov 12 at 17:40
Possible duplicate of Resize event for textarea?
– Ian
Nov 12 at 17:40
You also have
&&width=
which would be an invalid url string– Taplar
Nov 12 at 17:40
You also have
&&width=
which would be an invalid url string– Taplar
Nov 12 at 17:40
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
textarea
doesn't fire a resize
event when resized; that is for resizing the window. Instead, you can store the size of the textarea outside the function, and then check for changes when the mouse is released. Something like so would work:
let myTextArea = $('#myTextArea');
let oldHeight = myTextArea.height();
let oldWidth = myTextArea.width();
myTextArea.mouseup(function() {
let newHeight = $(this).height();
let newWidth = $(this).width();
if(newHeight !== oldHeight || newWidth !== oldWidth) {
console.log("Text area was resized!");
oldHeight = newHeight;
oldWidth = newWidth;
}
})
Note that this won't detect when the textarea
size changes for other reasons; for example when the window resizes. Also, to make it work for every text area on the page, you'd need to loop through them all and store their dimensions in an object so you could retrieve them.
add a comment |
up vote
0
down vote
.resize
does not work on a textarea element. I've just tested it myself. You can do this ;)
var textareaWidth;
var textareaHeight;
$('textarea').mouseup(function(evt) {
if(this.clientWidth != textareaWidth || this.clientHeight != textareaHeight) {
console.log(`new size= ${this.clientWidth} x ${this.clientHeight}`);
textareaWidth = this.clientWidth;
textareaHeight = this.clientHeight;
}
});
@Taplar I mean.resize()
does not work on a textarea element.
– Frank Roth
Nov 12 at 17:47
I've fixed it with two helper variables.
– Frank Roth
Nov 12 at 17:54
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
textarea
doesn't fire a resize
event when resized; that is for resizing the window. Instead, you can store the size of the textarea outside the function, and then check for changes when the mouse is released. Something like so would work:
let myTextArea = $('#myTextArea');
let oldHeight = myTextArea.height();
let oldWidth = myTextArea.width();
myTextArea.mouseup(function() {
let newHeight = $(this).height();
let newWidth = $(this).width();
if(newHeight !== oldHeight || newWidth !== oldWidth) {
console.log("Text area was resized!");
oldHeight = newHeight;
oldWidth = newWidth;
}
})
Note that this won't detect when the textarea
size changes for other reasons; for example when the window resizes. Also, to make it work for every text area on the page, you'd need to loop through them all and store their dimensions in an object so you could retrieve them.
add a comment |
up vote
1
down vote
textarea
doesn't fire a resize
event when resized; that is for resizing the window. Instead, you can store the size of the textarea outside the function, and then check for changes when the mouse is released. Something like so would work:
let myTextArea = $('#myTextArea');
let oldHeight = myTextArea.height();
let oldWidth = myTextArea.width();
myTextArea.mouseup(function() {
let newHeight = $(this).height();
let newWidth = $(this).width();
if(newHeight !== oldHeight || newWidth !== oldWidth) {
console.log("Text area was resized!");
oldHeight = newHeight;
oldWidth = newWidth;
}
})
Note that this won't detect when the textarea
size changes for other reasons; for example when the window resizes. Also, to make it work for every text area on the page, you'd need to loop through them all and store their dimensions in an object so you could retrieve them.
add a comment |
up vote
1
down vote
up vote
1
down vote
textarea
doesn't fire a resize
event when resized; that is for resizing the window. Instead, you can store the size of the textarea outside the function, and then check for changes when the mouse is released. Something like so would work:
let myTextArea = $('#myTextArea');
let oldHeight = myTextArea.height();
let oldWidth = myTextArea.width();
myTextArea.mouseup(function() {
let newHeight = $(this).height();
let newWidth = $(this).width();
if(newHeight !== oldHeight || newWidth !== oldWidth) {
console.log("Text area was resized!");
oldHeight = newHeight;
oldWidth = newWidth;
}
})
Note that this won't detect when the textarea
size changes for other reasons; for example when the window resizes. Also, to make it work for every text area on the page, you'd need to loop through them all and store their dimensions in an object so you could retrieve them.
textarea
doesn't fire a resize
event when resized; that is for resizing the window. Instead, you can store the size of the textarea outside the function, and then check for changes when the mouse is released. Something like so would work:
let myTextArea = $('#myTextArea');
let oldHeight = myTextArea.height();
let oldWidth = myTextArea.width();
myTextArea.mouseup(function() {
let newHeight = $(this).height();
let newWidth = $(this).width();
if(newHeight !== oldHeight || newWidth !== oldWidth) {
console.log("Text area was resized!");
oldHeight = newHeight;
oldWidth = newWidth;
}
})
Note that this won't detect when the textarea
size changes for other reasons; for example when the window resizes. Also, to make it work for every text area on the page, you'd need to loop through them all and store their dimensions in an object so you could retrieve them.
answered Nov 12 at 17:51
Ian
1,81631944
1,81631944
add a comment |
add a comment |
up vote
0
down vote
.resize
does not work on a textarea element. I've just tested it myself. You can do this ;)
var textareaWidth;
var textareaHeight;
$('textarea').mouseup(function(evt) {
if(this.clientWidth != textareaWidth || this.clientHeight != textareaHeight) {
console.log(`new size= ${this.clientWidth} x ${this.clientHeight}`);
textareaWidth = this.clientWidth;
textareaHeight = this.clientHeight;
}
});
@Taplar I mean.resize()
does not work on a textarea element.
– Frank Roth
Nov 12 at 17:47
I've fixed it with two helper variables.
– Frank Roth
Nov 12 at 17:54
add a comment |
up vote
0
down vote
.resize
does not work on a textarea element. I've just tested it myself. You can do this ;)
var textareaWidth;
var textareaHeight;
$('textarea').mouseup(function(evt) {
if(this.clientWidth != textareaWidth || this.clientHeight != textareaHeight) {
console.log(`new size= ${this.clientWidth} x ${this.clientHeight}`);
textareaWidth = this.clientWidth;
textareaHeight = this.clientHeight;
}
});
@Taplar I mean.resize()
does not work on a textarea element.
– Frank Roth
Nov 12 at 17:47
I've fixed it with two helper variables.
– Frank Roth
Nov 12 at 17:54
add a comment |
up vote
0
down vote
up vote
0
down vote
.resize
does not work on a textarea element. I've just tested it myself. You can do this ;)
var textareaWidth;
var textareaHeight;
$('textarea').mouseup(function(evt) {
if(this.clientWidth != textareaWidth || this.clientHeight != textareaHeight) {
console.log(`new size= ${this.clientWidth} x ${this.clientHeight}`);
textareaWidth = this.clientWidth;
textareaHeight = this.clientHeight;
}
});
.resize
does not work on a textarea element. I've just tested it myself. You can do this ;)
var textareaWidth;
var textareaHeight;
$('textarea').mouseup(function(evt) {
if(this.clientWidth != textareaWidth || this.clientHeight != textareaHeight) {
console.log(`new size= ${this.clientWidth} x ${this.clientHeight}`);
textareaWidth = this.clientWidth;
textareaHeight = this.clientHeight;
}
});
edited Nov 12 at 17:54
answered Nov 12 at 17:45
Frank Roth
2,99721624
2,99721624
@Taplar I mean.resize()
does not work on a textarea element.
– Frank Roth
Nov 12 at 17:47
I've fixed it with two helper variables.
– Frank Roth
Nov 12 at 17:54
add a comment |
@Taplar I mean.resize()
does not work on a textarea element.
– Frank Roth
Nov 12 at 17:47
I've fixed it with two helper variables.
– Frank Roth
Nov 12 at 17:54
@Taplar I mean
.resize()
does not work on a textarea element.– Frank Roth
Nov 12 at 17:47
@Taplar I mean
.resize()
does not work on a textarea element.– Frank Roth
Nov 12 at 17:47
I've fixed it with two helper variables.
– Frank Roth
Nov 12 at 17:54
I've fixed it with two helper variables.
– Frank Roth
Nov 12 at 17:54
add a comment |
Dmitry Khotinskiy is a new contributor. Be nice, and check out our Code of Conduct.
Dmitry Khotinskiy is a new contributor. Be nice, and check out our Code of Conduct.
Dmitry Khotinskiy is a new contributor. Be nice, and check out our Code of Conduct.
Dmitry Khotinskiy is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267288%2fresize-function-for-textarea%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Sorry, I miss-copied
– Dmitry Khotinskiy
Nov 12 at 17:36
So one code smell is that you are using
$.post()
without post data. You're sending data with a url query string.– Taplar
Nov 12 at 17:38
idownvotedbecau.se/itsnotworking
– connexo
Nov 12 at 17:38
Possible duplicate of Resize event for textarea?
– Ian
Nov 12 at 17:40
You also have
&&width=
which would be an invalid url string– Taplar
Nov 12 at 17:40