I have an HTML code with JavaScript that when clicking on top;
If x == 1
, it executes task A
and variable arrow javascript x = 0
, otherwise it executes task B
and variable arrow javascript x = 1
, however variable is restarted whenever function is started.
How to resolve?
JavaScript:
function toogle_m(MID, PID) {
if(x == 1) {
alert("Luck 7!"+"x");
var x = 0;
} else {
alert("You're not very locky today..."+"x");
var x = 1;
}
$(MID).fadeToggle(500);
$(PID).hide();
}
HTML:
<div class="F1" onclick="toogle_m(del)">
<img src='resources/images/andremachado/del.png' width='25' title='Excluir insumos'/>
</div>
I know it will restart because the function is always started, but what is the solution?