Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to change the label of a button on click event

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 376
    Comment on it

    Sometimes we need to change the label of a button on click event. Suppose you have button label as "Start" and you want to change that to "Stop" upon clicking start button.

    Example: In the below example I've created a function in which I'm changing label of button.

     

     <!doctype html>
        <html lang="en">
        <head>
        <meta charset="utf-8">
        <title>Demo</title>
        <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
        </head>
        <body>
        <button id="startButton" onClick="checkElement(this);">Start</button>
        <script>
    	function checkElement (e) {
    	   if (e.innerHTML == "Start")
    	   {
    	      e.innerHTML = "Stop";
    	   }
              else
              {
    	      e.innerHTML = "Start" ; 
    	  } 
    	}
    	
        </script>
        </body>
        </html>
    
    

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: