I've got the following code:
jQuery
$("li").click(function(){
$(this).toggleClass("selected");
$(".selected").each(function(){
$(".items").append(this.text() + ", ");
});
});
html
<ul class='category'>
<h4>Category</h4>
<a href="#"><li class="selected">Link 1</li></a>
<a href="#"><li>Link 2</li></a>
<a href="#"><li>Link 3</li></a>
<a href="#"><li class="selected">Link 4</li></a>
<a href="#"><li class="selected">Link 5</li></a>
<a href="#"><li>Link 6</li></a>
<a href="#"><li>Link 7</li></a>
</ul>
<span class="items">Selected Items Appear Here</span>
I'm trying to search the contents of the $(".category") for tags with the .selected class before appending the results to another div.
This is the result I'm hoping for:
<span class="items">Link 1, Link 4, Link 5</span>
However, the this.text() seems to be returning an undefined error.
Any clue as to what I'm doing wrong?