I want to add the list item chosen to the textarea and if there’s something written on the textarea the chosen list item will be added after it.
$('#box li').click(function() {
$('#id-of-your-textarea').append($(this).text());
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<ul id="box">
<li>Text1</li>
<li>Text2</li>
<li>Text3</li>
</ul>
<textarea id="id-of-your-textarea"></textarea>
2
Answers
So I edited your snippet and honestly, jQuery is too much. If you are learning, I would strongly advise you to learn pure Javascript. It is literally the code that runs under hood of jQuery library.
Below is the snippet that runs like you want with only Javascript, no jQuery, no library, just pure JS.
A pure/vanilla javascript solution could be for example: