How to find the text visible on the button with JavaScript?

JavascriptWeb DevelopmentFront End Scripts

To find the text visible on a button in JavaScript, use the innerHTML property.


You can try to run the following code to learn how to display the text visible −

 Live Demo

<!DOCTYPE html>
      <form id = "myForm">
         <button id = "btn" type = "button">My Button</button>
         var str = document.getElementById("btn").innerHTML;
         document.write("Button text: "+str);
Published on 26-Feb-2018 08:28:38