<html> <body> <div id="myDiv" style="width:100; height:100;">This is some sample text</div> <script language="javascript"> function function1(){ var temp = new String(); temp = myDiv.innerText; alert(temp); } </script> <button onclick="function1();">String function</button> </body> </html>