JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<h3>#1333</h3>
<p>Lorem ipsum</p>
<a class="comment" data-postid="1333">Add a comment</a>
</div>
JavaScript
$(document).ready(function () {
$("a.comment").click(function() {
var $this = $(this),
isOpen = !$this.next().length,
$textarea;
if (!isOpen) {
$this.next().focus();
return;
}
$textarea = $("<textarea/>");
$this.after(
$textarea
.after(
$("<button/>")
.text("Submit")
.click(
{$textarea: $textarea, postId: $this.attr("data-postid")},
submitComment
)
)
.after(
$("<button/>")
.text("Close")
.click(/* maybe do something here? */)
)
);
$textarea.focus();
});
});
submitComment = function (event) {
var message = event.data.$textarea.val(),
postId = parseInt(event.data.postId, 10);
alert("Do something with these:\nComment: " + message + "\nPost Id: " + postId);
};