Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the width of a textarea in jQuery?

Tags:

html

jquery

I want to set the width of a textarea to match the width of a particular image. Using .width() works for setting the width of an image, but not of a textarea.

$(document).ready(function() {
    var width = $("#my_image").width();
    $("#another_image").width(width); // works
    $("#my_textarea").width(width); // fails
});

How do I set the width of a textarea?

like image 886
AP257 Avatar asked Dec 30 '10 21:12

AP257


2 Answers

Use jQuery's css method like this:

.css("width", width)

or this, if you plan on setting more attributes:

.css({"width":width})

like image 95
Keith Avatar answered Sep 27 '22 15:09

Keith


You could try :

$("#my_textarea").css('width', width);
like image 43
Rion Williams Avatar answered Sep 27 '22 16:09

Rion Williams