Make appear and disappear html class by js

2

I have a registration page, and when the data is entered wrong, a alert(); appears informing the error, but I would like it to be an error message, just below the fields. I put a span with an error message and with the class sr-only of the boostrap that makes what I wrote remain invisible, but how do I use js to make the class disappear? would be in place of the alert that is in echo.

HTML
<span id="cpf"></span>Cadastrar</button>
<span class="sr-only">Dados incorretos.</span>

PHP
    echo"<script type='text/javascript'>alert('Alguém com esses dados já se cadastrou. Tente novamente.');window.location.href='cadastro.php';</script>";
    
asked by anonymous 06.12.2017 / 16:57

3 answers

2
document.getElementById("ID_DO_ELEMENTO").classList.remove("NOME_DA_CLASSE");
    
06.12.2017 / 18:05
0

To add or remove classes directly through javascript you can do the following:

To add

document.getElementById("seu-id").classList.add("sua-classe");

To remove

document.getElementById("seu-id").classList.remove("sua-classe");

More information

    
06.12.2017 / 18:58
0

If you are using JQuery, you can use the following code:

To remove class:

$( "seu-id" ).removeClass( "sua-classe" );

To add class:

$( "seu-id" ).addClass( "sua-classe" );

More information Add Class and Remove Class

    
06.12.2017 / 19:12