<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div id="click">click</div> <script type="text/javascript"> window.onload = function() { var c = document.getElementById("click"); var a = 1; c.onclick = function() { if (a==0) { a = 1; alert(a); } else { a = 0; alert(a); } } } </script> </body> </html>