Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get textarea content with jquery

I am new to jquery. I got struck with some function, I have two textarea boxes, let us suppose

the first textarea id is first_ta the second textarea id is second_ta

<textarea id="first_ta" rows="2" cols="2"></textarea>
<textarea id="second_ta" rows="2" cols="2"></textarea>

1. I want the content of first_ta in a "p" tag and the tag should be generated by jquery itself.

2. I want the content of second_ta in a "div" tag that should be generated by jquery and the div's id should be changed dynamically, if i repeat the process.

Please help me to find the solution for the above.

like image 980
user608082 Avatar asked Feb 08 '11 12:02

user608082


1 Answers

I want the content of first_ta in a "p" tag and the tag should be generated by jquery itself.

$('<p>').html($('#first_ta').val()).appendTo('body');

I want the content of second_ta in a "div" tag that should be generated by jquery and the div's id

// assuming you've got a variable genId defined somewhere in your code with a start 
// value of 1
$('<div>').html($('#second_ta').val()).attr('id', 'generated-id-' + genId++).appendTo('body');
like image 101
Aron Rotteveel Avatar answered Oct 13 '22 14:10

Aron Rotteveel