the code:
<style> .demo {color: yellow; background-color: purple} </style> <p class="demo">my text</p> <button id="change">click</button> <script> window.onload = function () { var flipColors = query("#change"); var target = query(".demo"); flipColors.onclick = function() { style(target, "color", "white"); style(target, "background-color", "black"); }; }; </script>
When I press the button, the style changes.
My question is what I need to add to JS when the button clicks again - it will restore the original style, and if you click it again, it will activate the function again instead of two buttons.
I know that I can create .demo
and .demo1
and switch them, but I want to understand how to do this, if possible.
Note. Just JS, not jQuery, etc.
source share