Web Analytics Made Easy -
StatCounter How to read text in HTML - CodingForum

Announcement

Collapse
No announcement yet.

How to read text in HTML

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to read text in HTML

    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">
    Hello!
    </font>
    ...

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

    Thank you.

  • #2
    i don't know if this is exactly what you want:

    <font id="greet" size="3">
    Hello!
    </font>

    then you can do this:

    if (document.all) obj = document.all["greet"];
    else if (document.getElementById) obj = document.getElementById("greet");
    alert(obj.innerText)
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      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.
      Scripting | JavaScripts | PerlScripts | Python Scripts | Articles | My Journal

      Comment


      • #4
        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.

        Thanks.

        Comment


        • #5
          maybe it's possible with DOM, try to post this to DOM scripting forum or maybe the moderators can move it themselves.
          Glenn
          vBulletin Mods That Rock!

          Comment

          Working...
          X