<html> <body> <script language="JavaScript"> function function1() { var myText = myButton.createTextRange(); alert(myText.duplicate().text); } </script> <button id="myButton" onclick="function1();">Click this button</button> </body> </html>