Infinitescroll在检索后获得第一个元素

时间:2015-05-24 07:44:49

标签: javascript jquery html infinite-scroll

我在我的网站上使用Infinite scroll。当我向下滚动时它很好。但是在按钮上单击我试图获取数据。所以我用过:

nextpage = $('.selector').infinitescroll('retrieve');

这里我的下一页已添加。但我希望添加下一页的第一个元素。所以我试图从变量“nextpage”中找到第一个元素并从第一个元素中获取:

firstelement = nextpage['0'].firstElementChild.innerHTML
console.log(nextpage['0'].firstElementChild.innerHTML);

这是第一个元素,但这只是文本版本而不是html dom,所以我试图从第一个元素中找到一个图像“.imglazy”,所以我在下面尝试过这个。

 firstelement = firstelement.parseHTML();
 firstelement.find('.imglazy').attr('src');

但这不起作用。谁能帮助我找到下一页的第一个元素?我的过程是错的吗?请帮帮我。

由于

2 个答案:

答案 0 :(得分:2)

尝试记录结果,你可以得到一些结果:

 console.log(nextpage);

答案 1 :(得分:1)

使用jquery获取html

var firstelement = $('.selector').children().find(':first-child').html();

对于图像,您可以使用

var imagefromfirstelement = $('.selector').children().find(':first-child .imglazy').attr('src');

希望有所帮助

相关问题