SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard silver trophybronze trophy asp_funda's Avatar
    Join Date
    Jun 2003
    Location
    ether
    Posts
    4,497
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question Getting text from between two tags?

    hi
    what I'm trying to do is get text from between two tags, just like the title says. Now I know I can get that through the innerHTML property, but its just that, I don't want HTML, I want plain text. Consider the following example.
    HTML Code:
    <span id="p-5641">
    This is <strong>strong</strong> & you should really put <em>emphasis</em> on that <a href="#">anchor</a>.<br>Line broken
    </span>
    Now, what I want is, to get the text from between these span tags. That can be done by refering the ID of the span & innerHTML but that would give HTML & I want to strip off the HTML from it, so that I'm left with plain text, like
    HTML Code:
    This is strong & you should really put emphasis on that anchor.
    Line broken
    with <br> & <p> tags preserved.

    Can anyone help?
    Our lives teach us who we are.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Me - Photo Blog - Personal Blog - Dev Blog
    iG:Syntax Hiliter -- Colourize your code in WordPress!!

  2. #2
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well you could use innerHTML then use PHP strip_tags() to remove the HTML. I don't know if using PHP is an option for you, though.
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ::: certified wild guess :::

  4. #4
    SitePoint Wizard silver trophybronze trophy asp_funda's Avatar
    Join Date
    Jun 2003
    Location
    ether
    Posts
    4,497
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Possibility, I'd rather not involve PHP or any server side language in it.
    I was thinking of doing it only in JavaScript on the client side but if
    there's no other option, then I think I'll use XMLHttpRequest trick like
    Simon mentioned at http://www.sitepoint.com/blog-post-view.php?id=185942

    Adios, that link tells how to iterate between a table elements & manipulate
    them. I don't understand how could it solve my problem.
    Our lives teach us who we are.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Me - Photo Blog - Personal Blog - Dev Blog
    iG:Syntax Hiliter -- Colourize your code in WordPress!!

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    Durham
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by asp_funda
    Adios, that link tells how to iterate between a table elements & manipulate
    them. I don't understand how could it solve my problem.
    Look closer at what the page adios linked to is telling you. It iterates through the childNodes of the element you specify picking out only the text nodes. It then strips any unneeded whitespace. It does exactly what you asked for... (just look at the stuff above "Comparing Values")

  6. #6
    SitePoint Wizard silver trophybronze trophy asp_funda's Avatar
    Join Date
    Jun 2003
    Location
    ether
    Posts
    4,497
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Oh ok.
    Our lives teach us who we are.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Me - Photo Blog - Personal Blog - Dev Blog
    iG:Syntax Hiliter -- Colourize your code in WordPress!!


Bookmarks

Posting Permissions

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