Reputation: 15
<div class="count">5</div>
<div class="count">6</div>
How do I get the values of the text nodes? If I use text() method, it concatenates both values.
Upvotes: 1
Views: 2528
Reputation: 4666
what about
$("div.count:first").text();
if you have several and want to get 3rd for instance you could do
$("div.count:eq(2)").text();
Upvotes: 0
Reputation: 7597
You will need to loop the collection that results from $(".count")
, and then grab the text()
value of each in the loop.
Upvotes: 0
Reputation: 37029
Use map if you want an array of the text values, eg.
$('div.class').map(function() { return $(this).text(); })
Upvotes: 2