I'm trying to compare one item <span class="x">123</span>
with a group of items on one page to check if the first item mentioned already exists in the list:
<div class="y">
<span class="z">123</span>
<span class="z">234</span>
<span class="z">345</span>
</div>
How could I开发者_C百科 get the values of <span class="z">
to be assigned to an array?
var arr = [];
$('.z').each(function(idx,el) {
arr[idx]=parseInt($(this).text(),10);
});
In jQuery this is available.
$(".z").each(function(){
alert($(this).html());
});
var retVar = [];
$('.z').each(function(idx,el) {
retVar.push(parseInt($(this).text(),10));
});
How about using map
var array_vals = $(".y").children().map(function() { return $(this).text(); });
精彩评论