Imagine you have multiple text areas like the ones below:
<textarea class='save'></textarea>
<textarea class='save'></textarea>
<textarea class='save'></textarea>
All of them are assigned the class 'save'. The goal is to use jQuery/JavaScript to extract the text from each textarea with the 'save' class.
Here's what I've come up with so far:
$('#getText').click(function(){
var text = $('.save').text();
});
With this code, all the text values are retrieved and stored in the variable. However, I'd prefer to loop through each textarea first for potential editing. Here's my conceptual plan:
On button click -> Retrieve first '.save', encapsulate it within <p></p>, include a
<h1>Title</h1>, and store this in a variable/array.
The output format would be as follows:
<h1>Text 1</h1>
<p>text from textarea 1</p>
<h1>Text 2</h1>
<p>text from textarea 2</p>
<h1>Text 3</h1>
<p>text from textarea 3</p>
This process should be repeated for each '.save'. Any suggestions on how to achieve this?