Reputation: 1779
I am using
function example_append() {
$('#containment').append($('#example-textarea').val());
}
This is throwing the text I put in the form field in to the div #containment. I'd like to place the value of the form field into the containment div, but also have it wrapped in a div with a class name so I can style it. Is this possible?
Also, the user inserts the text via the form field and it gets thrown into that div, how could I remove that string of text if the user wants to start over?
Upvotes: 0
Views: 168
Reputation: 3951
These two functions should do what you're looking for. Just bind reset_text
to a button or text on click.
edit Added event bind for clearing text.
function example_append() {
$('#containment').append(
$('<div />').addClass('className').text($('#example-textarea').val())
);
}
$(document).ready( function() {
$('#example_button').on('click', reset_text );
});
function reset_text() {
$('#example-textarea').val('');
$('.className').remove():
}
Upvotes: 1
Reputation: 1725
you can do this :
var div = $('#example-textarea').val();
$('#containment').append(div.wrap('<div class="new" />'));
that wraps the value in a div with class "new" and to remove the textarea value, just do this :
$('#example-textarea').val('')
Upvotes: 1