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.

Example

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

 Live Demo

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