开发者

How to get multiple span item content on a page based on single class property value

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(); });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜