Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript toggle button

<button id="btn"> Click </button>

<p class="demo">YES</p>

<script>
	let btn = document.querySelector("#btn");
    
	btn.addEventListener("onclick", function() {
    	let value = document.querySelctor("#demo").innerHTML;
      
      	if(value == "YES"){
          document.querySelctor("#demo").innerHTML = "NO";
        }else{
           document.querySelctor("#demo").innerHTML = "YES";
        }
    });

</script>
Source by www.delftstack.com #
 
PREVIOUS NEXT
Tagged: #javascript #toggle #button
ADD COMMENT
Topic
Name
4+5 =