how do I make the recently published comments go down

0

I have a comment box but the comments just published puts them first, and I want them to go last. from bottom to top "al réves" type chat messages.

<main class="centered-bottom" id="main" role="main" tabindex="-1">

from there to below they go pure <article></article>

How do I do?

    
asked by codigofanatico 08.07.2018 в 05:26
source

2 answers

1

Only with javascript you could do something like this, in this example with each message you create a new p and become a child of div comments, so each new comment is placed below the previous one.

var comentarios = document.getElementById("comentarios");
function enviar() {
  var p = document.createElement("p");
  comentarios.appendChild(p);
  p.innerHTML = document.getElementById("input").value;
}
.comentarios {width:200px;height:200px;}
<input type="text" id="input">
<input type="button" id="boton" value="Enviar" onclick="enviar()">
<div class="comentarios" id="comentarios"></div>
    
answered by 08.07.2018 в 13:42
0

I have another solution with Jquery :

$('#boton').click(function(){
    $('#comentarios').append( $('#cajaTexto').val() + "<br>" );
    $('#cajaTexto').val('');
});
<input type="text" id="cajaTexto">
<input type="button" id="boton" value="Enviar"">
<div class="comentarios" id="comentarios"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    
answered by 08.07.2018 в 19:34