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 get current date format dd mm yyyy hh mm ss 
Javascript :: javascript get date 
Javascript :: pushing element in array in javascript 
Javascript :: pipe data to json angular 
Javascript :: reactjs get url query params as object 
Javascript :: how to set a string 
Javascript :: nodejs event 
Javascript :: swiperjs cdn 
Javascript :: server.js 
Javascript :: remove item at index in array javascript 
Javascript :: selected angular select 
Javascript :: mdn foreach 
Javascript :: javascript redirect to url with parameters 
Javascript :: replace componentwillmount with hooks 
Javascript :: react bootstrap carousel caption placement top 
Javascript :: angular ngmodel checkbox 
Javascript :: javascript array size 
Javascript :: how we link external js file in laravel 9 project 
Javascript :: google auth.onstatechange 
Javascript :: jquery is not defined rails 
Javascript :: Map in Javascript in LWC 
Javascript :: set attribute using each jquery 
Javascript :: suspense react 
Javascript :: javascript type casting int 
Javascript :: convert string to unicode javascript 
Javascript :: find and filter 
Javascript :: node js return ID in postgres insert 
Javascript :: node.js query parameters 
Javascript :: jquery is element hidden 
Javascript :: js tolowercase 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =