SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict blizzman24's Avatar
    Join Date
    Jul 2004
    Location
    Texas
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how do I access the text between tags?

    for example I have an array of List elements.

    HTML Code:
    <ul id="my_div">
    <li>
    <div class="title">title1 here</div>
    <div class="message"><a href="#">message1</a></div>
    </li>
    <li>
    <div class="title">title2 here</div>
    <div class="message"><a href="#">message2</a></div>
    </li>
    ...
    </ul>
    I iterate through each list element, and do something like:

    $("#my_div").each(function(){
    $(this).find(".message").html();
    });

    this code will give me <a href="#">message1</a>

    but is there a way to just get "message1" ????

  2. #2
    SitePoint Addict Zarin Denatrose's Avatar
    Join Date
    Jan 2009
    Location
    Surrey BC, Canada
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There absolutely is, and you already know it.
    As it is, you're getting the html between the opening and closing tags of .message . To go one step further, just make it select the anchor tag inside .message blocks instead.

    $("#my_div").each(function(){
    $(this).find(".message a").html();
    });

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,084
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Or just

    Code javascript:
    $("#my_div a").each(function(){
      $(this).html();
    });

    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


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
  •