-5
Personal how could I make a button that changes text and icon when clicked? and click again return to the original button? could help me
function mostrar(e) {
if (e.classList.contains("glyphicon-plus")) { //se tem olho aberto
e.classList.remove("glyphicon-plus"); //remove classe olho aberto
e.classList.add("glyphicon-minus"); //coloca classe olho fechado
} else {
e.classList.remove("glyphicon-minus"); //remove classe olho fechado
e.classList.add("glyphicon-plus"); //coloca classe olho aberto
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<form method="POST">
<button type="button" class="btn glyphicon glyphicon-plus" onclick="mostrar(this)"> save </button>
</form>
You are already changing the icons, just change the text, on if/Else just put a
e.innerText = ' Texto que quer'
– LeAndrade
@Leandrade by the image the direction of the icone is also on the wrong side, in fact being glyphicons should use a subelement
<i class="glyphicon glyphicon-plus">
, after the text and text maybe within a<span>
;– Guilherme Nascimento
@Guilhermenascimento I already managed to do brother, only problem is that now I can’t leave the icon on the direct side, how could I do that?
– Matheus Prestes
@Guilhermenascimento <button type="button" class="btn glyphicon glyphicon-plus" onclick="show(this);incrementClick()"> Save</button> ?
– Matheus Prestes
Create an element
<i>
with the classesglyphicon glyphicon-plus
and in the elementbutton
remove the classesglyphicon glyphicon-plus
, the<i>
should be on the right side of the text and the text should preferably go within one element<span>
so that you can edit it via JS without affecting the element<i>
.– Guilherme Nascimento
@Guilhermenascimento I made here man, it did not work, I tried several ways already
– Matheus Prestes