Currently, I am in the process of developing a basic chat bot. Upon receiving a new message from the server, a fresh HTML element is generated and sent to the browser. For instance, when message 1 is received, it will appear as follows:
<div class="message-computer"><p>Hi, how are you?</p></div>
Subsequently, the user types or sends a response, which will display like this:
<div class="message-user"><p>I am good, thanks!</p></div>
This cycle continues with each exchange between the server and user. As part of the functionality, I implemented a slider interface that allows users to adjust the text size being transmitted through the chat bot. While this feature does currently work, it only alters the font size of existing HTML elements. The newly incoming messages still maintain the original size.
To provide uniformity in font size across all message elements, I crafted the following JavaScript code snippet:
$('input').on('change', function() {
var v = $(this).val();
$('.message-computer p').css('font-size', v + 'em')
$('.message-user p').css('font-size', v + 'em')
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="range" value="1" min="1" max="1.6" step=".1" id="slider" ondrag="changeSize()" />
If you have any suggestions or solutions on how to extend the font size adjustment functionality to encompass all new message elements, please do not hesitate to share your insights.
Appreciate it!