How to set width of text area in jQuery?

I want to set the width of the text area to fit the width of a particular image. Using .width() works to set the width of the image, but not the text area.

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

How to set the width of the text area?

+10
source share
3 answers

Use jQuery css for example:

.css("width", width)

or this if you plan to set additional attributes:

.css({"width":width})

+15
source

You can try:

 $("#my_textarea").css('width', width); 
+1
source
 $("#my_textarea").css('width',width); 

Also you can use . outerWidth () to set var width depending on indentation / margin / border settings

+1
source

All Articles