Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

toggle button by javascript

<!DOCTYPE html>
<html>
<head></head>
<body>
<form>
<input type="button" id="myButton" value="NO"
       onclick="Buttontoggle();">
</form>
</body>
<script type="text/javascript">
function Buttontoggle()
{
  var t = document.getElementById("myButton");
  if(t.value=="YES"){
      t.value="NO";}
  else if(t.value=="NO"){
      t.value="YES";}
}
</script>
</html>
Comment

toggle button javascript

<input type="button" id="myButton" value="NO" onclick="Buttontoggle();">

function Buttontoggle()
{
  var t = document.getElementById("myButton");
  if(t.value=="YES"){
      t.value="NO";
  } else if(t.value=="NO"){
      t.value="YES";
  }
}
Comment

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>
Comment

toggle function in javascript

let flag = false;

const toggle = () => {
	if ( flag ) {
     // insert code here when flag is on/true
    } else {
    // insert code here when flag is off/false
    }
    flag = ! flag;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript reverse 
Javascript :: javascript duplicate an array 
Javascript :: node js ffmpeg image to video 
Javascript :: how to install jsonwebtoken in next js 
Javascript :: axios get 
Javascript :: looping through an array javascript sum 
Javascript :: javascript debounce 
Javascript :: jquery chrome extension 
Javascript :: read multiple parameters in url in js 
Javascript :: how to find duplicates in an array 
Javascript :: material app routes 
Javascript :: express command not found mac 
Javascript :: javascript fast inverse square root 
Javascript :: js how to sort strings in array 
Javascript :: pass multi variable in ajax 
Javascript :: looping queryselectorall 
Javascript :: prime number in javascript 
Javascript :: redux toolkit with redux persist 
Javascript :: check href javascript 
Javascript :: check if a date is more than 18 years javascript 
Javascript :: jquery validation focus field on error 
Javascript :: how to know if select input has been selected in js 
Javascript :: How to Close a React Native Modal with a Button 
Javascript :: how to flat an array in javascript iteratively 
Javascript :: ajax mdn 
Javascript :: node.js copy to clipboard 
Javascript :: js parse url 
Javascript :: sequelize array of strings 
Javascript :: how to write a program that shows a random number between 1 and 100 in your browser 
Javascript :: api.fetch saga 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =