How do I access the text between tags?

for example I have an array of List elements.


<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” ???

Or just


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

:slight_smile:

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();
});