[jQuery] Using each() to check for content

[jQuery] Using each() to check for content


I have a listing of links that are titles for items in my database.
Each item might have a description in the database as well, so I was
wanting to print the description, then replace it with a * if there is
any text for the description. The descriptions contain HTML such as
links, so inserting this into my anchor tag makes it invalid HTML,
which I understand. But I remove it from the DOM and replace it with
a *. Strange thing is, it does not seem like it is getting removed
correctly and replaced.
Any ideas why this might be happening? (And yes, like I said, I
understand it is incorrect HTML, but since it gets replaced almost
instantly, I didn't think this would be a problem.)
I am using:
$(document).ready(function() {
$(".test").each(function() {
if ($(this).html() == "") {
//Do nothing
} else {
$(this).html("*");
}
});
});
My links that need the content replaced:
<div class="itemHolder"><a>Item Name<span class="test">

Contents <a
href="#">Link</a>

</span></a></div>
<div class="itemHolder"><a>Item Name<span class="test">

Contents <a
href="#">Link</a>

</span></a></div>
<div class="itemHolder"><a>Item Name<span class="test">

Contents <a
href="#">Link</a>

</span></a></div>