Javascript, writing dynamic content to textarea
I am programming a bl开发者_开发技巧og in php, for the record I've just started out but Im doing pretty good with this PHP but Javascript I don't really understand.
On my blog I would like people to comment and discuss.
What I want:
Every comment has an id that is displayed.
I want to click on it and then the Javascript should place it in the textarea for leaving comments.
Thats all.
(This answer uses jQuery.)
// getting a reference to the TEXTAREA element
var $ta = $("#new_comment textarea");
$(".comment").click(function() {
var text = $(this).find(".text").text(); // depends of the structure
$ta.val(text);
});
<div class="comment">
<p class="author"> Peter </p>
<p class="text"> Good article! </p>
</div>
精彩评论