1
How can I get my div, whose text is added through a append
jQuery, scroll when the text reaches 100px
, and all the added text then stay hidden, and you need to scroll to see the rest?
$('#sendMessage').click(function() {
if ($.trim($('#inputToSend').val()) == '') {
//do not send anything
} else {
$('.textModal').append('<p class="msg" style="margin-bottom: 25px; position: absolute;">' + $('#inputToSend').val() + '</p>' + '<br>');
$('#inputToSend').val('').focus();
}
});
.textModal {
margin: 0px 15px;
font-size: 16px;
padding: 10px;
border: inset;
height: 100px;
overflow: auto;
text-align: justify;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="messageInput">
<div class="textModal"></div>
<input id="inputToSend" type="text" class="text form-control" placeholder="Insert Message...">
<button id="sendMessage" class="btn btn-primary">Enviar</button>
</div>