Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    maybe it's possible with DOM, try to post this to DOM scripting forum or maybe the moderators can move it themselves.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •