<div onclick=" if ((zamanux = 'undefined')||(zamanux=0)) {document.getElementById('zam').style.right='-75px'; zamanux=1;} else {document.getElementById('zam').style.right='0px'; zamanux=0;}; "> 

for some reason, even after the first click, the zamanux variable remains undefined ... i.e. I want the right property to change to -75 by the first press ... and to return to 0 again on the second ... but it works only in one direction, but does not change to 0

    2 answers 2

     if(zamanus === undefined) { //чета делаем zamanus = true; } else { //чета делаем... zamanus = undefined; } 

    typical switch example ...

    UPD
    all because of the variable zamanus, should be defined in the script, I thought it was obvious ...
    Well, here's a working example:

      <script type="text/javascript"> var z = undefined; </script> <div onclick=" if(z === undefined) { this.style.color='red'; z = true; } else { this.style.color=''; z = undefined; } "> Клацни и я буду менять цвет </div> 
    • Well, I do this ... only for some reason that zamunux = 1 does not linger in the computer's memory ... if you put alert (zamanux) after this line, 1 will pop up on the screen ... but after that, by pressing, the else condition should work ... but for some reason all the same if works - Nuboyd
    • do you think zamanux = 'undefined' and zamanux === undefined same thing? - Zowie
    • I tried as you write, not rolled - Nuboyd
    • if ((zamanux = 'undefined') || (zamanux = 0)) {document.getElementById ('zam'). style.right = '- 75px'; alert (zamanux); zamanux = 1; alert (zamanux);} ... again ... after the first press, the screen displays 'undefined' first, and then '1' ... i.e. the condition worked ... but when you press it again, the zamanux variable is already equal to 1, in theory, therefore the else condition should work .. but for some reason it still works if it again returns 'undefined' first and then '1' again ... that feeling that the variable did not remain in memory after the first click - Nuboyd
    • see above, we understand that in our case we need a global variable, change the code - <b> profit </ b> - Zowie

    if ((zamanux = 'undefined')||(zamanux=0))

    Hardly both times you want to assign (the first time the string "undefined", the second - the number 0).

    • I did not understand ... if ((zamanux = 'undefined') || (zamanux = 0)) - this condition handles two situations, for the first time I poked a block with id = zam or 3, 5, 7 - Nuboyd
    • The meaning of if'a is to find out if it is zero or undefined? - ivkremer
    • @ Nuboyd , meet - Dex
    • yes ... if not equal then else - Nuboid
    • Then double all the same zeal ) - ivkremer