tinfanide Posted July 18, 2011 Share Posted July 18, 2011 <textarea>Content to be added</textarea> Suppose I'll use JS to add in more content to the textarea. I wonder if in CSS there's any way to determine the height of the textarea by the flexible size of the content? It means if I add in more, the textarea will expand WITHOUT SCROLLING needed. Link to comment Share on other sites More sharing options...
Ingolme Posted July 18, 2011 Share Posted July 18, 2011 I'm pretty sure it's not possible. The only thing you can do is find a way to detect the height of the content in Javascript and resize the textarea accordingly using the onkeyup event. Link to comment Share on other sites More sharing options...
tinfanide Posted July 18, 2011 Author Share Posted July 18, 2011 I'm pretty sure it's not possible. The only thing you can do is find a way to detect the height of the content in Javascript and resize the textarea accordingly using the onkeyup event.I see what ya meant. It might be JS that can do the job. It's not onkeyup though, I reckon as my textarea is only to show the texts, not to let users type the texts. So I don't think onkeyup is effect. Link to comment Share on other sites More sharing options...
jeffman Posted July 18, 2011 Share Posted July 18, 2011 my textarea is only to show the texts, not to let users type the textsIf that is true, then a textarea is probably not the right element to use. Textareas exist so that users can enter text. That's it.If you assign some text to the innerHTML of a <div> or <p> element instead, the height should adjust automatically.If there is something about the default appearance of a textarea that appeals to you, you can certainly use CSS to give that same appearance to a <div> or <p> element. Link to comment Share on other sites More sharing options...
tinfanide Posted July 18, 2011 Author Share Posted July 18, 2011 If that is true, then a textarea is probably not the right element to use. Textareas exist so that users can enter text. That's it.If you assign some text to the innerHTML of a <div> or <p> element instead, the height should adjust automatically.If there is something about the default appearance of a textarea that appeals to you, you can certainly use CSS to give that same appearance to a <div> or <p> element.That' exactly what I thought shortly after I'd posted this question.I've quite mixed up the two different uses of them. Textarea should not be like that. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.