WEB simple way to take the text from a div but ignore the inner html?

Discussion in 'OT Technology' started by White Stormy, May 26, 2008.

  1. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    so like if I have
    Code:
    <div id="ThomorSucks">
      <span class="redpoop">turkey chicken tits</span>
    </div>
    
    how can I grab JUST "turkey chicken tits"? I know the id of the container, but not what html may be inside it. I'm a javascript noob, so the only thing I really know to do is to write a function to strip out any html code.. is there something built in? or just a better method?

    tia
     
  2. Insert Tokens

    Insert Tokens Making Cancer My Bitch OT Supporter

    Joined:
    Jan 12, 2006
    Messages:
    8,329
    Likes Received:
    75
    Location:
    Tasmania
    <SCRIPT LANGUAGE="JavaScript">
    var htstring = '<p align="Left"><b>Hello</b> <I>World</I></p>';
    var stripped = htstring.replace(/(<([^>]+)>)/ig,"");

    with (document) {
    write ('Original string:' + htstring + '<br>');
    write ('Stripped string:<br><br>' + stripped);
    }
    </SCRIPT>


    Searched "strip html with javascript" in google, got above from: http://zamov.online.fr/EXHTML/DHTML/DHTML_983246.html

    :)
     
  3. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    :big grin: thanks

    that works perfect
     
  4. 96

    96 Merry Christmas :D

    Joined:
    Oct 30, 2001
    Messages:
    16,073
    Likes Received:
    0
    Location:
    San Diego
    jQuery.


    .text() ;)
     

Share This Page