Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading HTML text.

Status
Not open for further replies.

vasilek

Programmer
Jan 5, 2003
99
US
Hi. Can JavaScript read the text in HTML file that is outside of <script></script> tags? Thanks.
 
yes using the innerHTML attribute.

<div id=&quot;test&quot;>this text will appear on screen friend.</div>
<script>
alert(document.getElementById(&quot;test&quot;).innerHTML)
</script>




Gary Haran
********************************
 
What if the text is not inside of <div> tag with id attribute? What are the other options?

<HTML>
<HEAD>
<TITLE>Main</TITLE>
</HEAD>
<BODY BGCOLOR = &quot;#ffffff&quot;>
<FONT FACE = &quot;Arial, Helvetica&quot;>
My text is located here.
</FONT>
</BODY>
</HTML>
 
[tt]alert(document.body.innerText)[/tt]

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top