(function() { // FUNCTION TO ADJUST TEXTAREA HEIGHT AND SUBMIT BUTTON VISIBILITY function adjustTextAreaAndButton(textarea, submitButton) { // Adjust the height of the textarea if (textarea.value.trim() === '') { textarea.style.height = '50px'; } else { textarea.style.height = textarea.scrollHeight + 'px'; } // Display and hide the submit button if (textarea.value.trim() === '') { submitButton.classList.add('hidden'); } else { submitButton.classList.remove('hidden'); } } // INITIALIZE ELEMENTS const form = document.querySelector('#sendMessage'); const textarea = document.querySelector('#dynamicTextarea'); const conversationContainer = document.getElementById('conversation'); const submitButton = document.getElementById('submitMessageButton'); // EVENT LISTENERS textarea.addEventListener('input', () => adjustTextAreaAndButton(textarea, submitButton)); form.addEventListener('submit', (event) => { textarea.style.height = '50px'; submitButton.classList.add('hidden'); setTimeout(() => { conversationContainer.scrollTop = conversationContainer.scrollHeight; }, 100); }); })();