onclick lasting 1 second

Asked

Viewed 16 times

0

Man onclick this one lasting only 1 second.

Ex: I click the right button and take the value of the input and return to div, but the value is only lasting 1 second on the screen:

function teste() {
    let input = document.querySelector('#chat-input')
    let value = input.value
    let div = document.querySelector('#conversa')
    div.innerHTML = value
    div = div
}
.chat div, img, input, button {
 padding: 10px;
}

.chat img {
 width: 25px;
 height: 25px;
}
<div class="chat">
    <img src="./img/sp.png" alt="Logo suporte">
    <i class="fas fa-times"></i>
    <div id="conversa"></div>
    <form action="">
        <label class="sr-only" for="description">Descrição</label>
        <input type="text" id="chat-input" placeholder="Qual a sua duvida?" />
        <button type="submit" onclick="teste()">Enviar</button>
    </form>
</div>

  • You are submitting the form. To resolve this, change the type of the button to button: <button type="button" onclick="teste()">Enviar</button>

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.