JSFiddle - React, Tailwind, and code Playground
HTML
<div id="parent">
<span>One </span><span>Two</span><span>Three</span>
<form action="/test/index6.html" method="get">
<textarea id="thediv" name="thediv"></textarea><br>
<input type="submit" />
</form>
<input type="button" id="clear" value="Clear" />
<script type="text/javascript">
</script>
</div>
JavaScript
$("#parent").delegate("span", "mousedown", function() {
console.log($("#thediv").text());
if ( $("#thediv").text().indexOf($(this).text()) <0 )
{
$("#thediv").append($(this).text());// get old div contents and add clicked word
$("#thediv").append(' ');// also add a space
$("#thediv").html(); //print to div
};
});
$('#clear').click(function (){
$("#thediv").html('');
});