Computer >> Computer tutorials >  >> Programming >> Javascript

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


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 −

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