Reputation: 677
I have a textarea that serves as input for text. When clicking a submit button, I want that text to be introduced in an html post structure, and that post (the html+text) to be appended to a list as a new post/comment.
JS:
var post= $('.small-textarea').val();
$("#comment-feed-list").append('<div> some text' + post + 'end</div>');
I am not being able to do it with success.
Is this an effective way to do it?
Thanks in advance.
Upvotes: 0
Views: 1230
Reputation: 1154
If you're doing it on submit, you have to prevent the actual submit event from happening
$('#myForm').submit(function(e){
e.preventDefault();
var post= $('.small-textarea').val();
$("#comment-feed-list").append('<div> some text' + post + 'end</div>');
});
The more common case is to prevent the submit, then send an ajax request to update the server behind the scenes and then append data to the DOM in a success callback or whatnot.
Upvotes: 1