View Full Version : How to read text in HTML

07-09-2002, 05:25 AM
I am new to Javascript so my questions would be very simple (or even stupid).

My question is, if I want to extract a specific text in a HTML page, how can I do it? For example, part of the HTML page will look like this:

<font size="3">

I want to know how to extract the word "Hello" by using Javascript.

Thank you.

07-09-2002, 07:33 AM
i don't know if this is exactly what you want:

<font id="greet" size="3">

then you can do this:

if (document.all) obj = document.all["greet"];
else if (document.getElementById) obj = document.getElementById("greet");

07-09-2002, 08:25 AM
Whenever you want to extract the contents (text) of a HTML file it is always good to use <DIV id="idName"> tags in case of IE, NS6+ and <layer id="idName"> in case of NS4.

You can get the text within the element as Glenn said.

07-09-2002, 08:44 AM
OK, but that wouldn't solve my problem. I am sorry I forgot to mention the most important part - I am only allowed to append Javascript function(s) to the **ORIGINALLY EXISTING** HTML file. Therefore, I can't change the original "<font size="3">" tag into <font id="id name"> tag.

Your suggestion is to identify the content by a unique id, however, I need to identify the content by its exact value, say, the text "Hello" in my previous example.

If anyone has more suggestion, pls kindly let me know. Or, if you think it is not possible to do it, pls also let me know.


07-09-2002, 09:01 AM
maybe it's possible with DOM, try to post this to DOM scripting forum or maybe the moderators can move it themselves.