Reputation: 11745
I have a div in which I have spans and I want to read all the text of the inner span. I am not able to read the span "name" text. What is wrong with the following piece of code?
<div id= "myList">
<span class="FirstSpan">
<span class = "name">
</span>
</span>
</div>
var values= [];
$('#myList').find('span.name').each(function () {
$alert($(this).html());
values.push($(this).html());
});
Upvotes: 2
Views: 475
Reputation: 87073
$alert()
should be alert()
you can try
$(this).text()
Full code
var values = [];
$('#myList span.name').each(function () {
alert($(this).text());
values.push($(this).text());
});
Other way:
var values = [];
$('#myList span.name').text(function(i, text) {
alert(text);
values.push(text);
});
Related refs:
Upvotes: 3
Reputation: 145478
There is no function $alert()
and that is the problem. Use alert()
instead.
However, in your case I'd better use map
method:
var values = $("#myList span.name").map(function() {
return $.trim(this.innerHTML);
}).get();
DEMO: http://jsfiddle.net/m5QsA/
Upvotes: 1