-1
Good morning, I’m new with javascript and I’m having a hard time creating a button where mine always changes my H2 to +1, follow my code:
<body>
<script src="script.js"></script>
<h1 style="text-align: center;">SENHA</h1>
<h2 style="text-align: center;">0</h2>
<div style="text-align: center;">
<button id="count" >Nova Senha</button>
</div>
<br>
<form style="text-align: center;"><input type="button" value="IMPRIMIR" onClick="window.print()"/></form>
</body>
</html>
var cont = 0; Function counter(){ Let button = Document.getElementById("btn"); Let H2 = Document.getelementsbytagname("H2");
cont++;
}
I need 0 to start adding +1 every time I click on a new password, someone knows what I have to do to fix the code ??
The function
contador
is not called in your code; and if it is, only changes the variablecont
, not used in the code.– Woss
What do you mean it’s not called in my code? I call it in the <script>
– Welleson De Andrade Silva
In the code that posted in the question it is not called. If it really is in your code, I ask you to elaborate then a [mcve] demonstrating the problem
– Woss