无法获取类jquery的最后一个子级
因此,当用户滚动通过我的索引页面中的div时,我实现了加载更多数据 我的div包含数据:无法获取类jquery的最后一个子级,jquery,html,jquery-selectors,Jquery,Html,Jquery Selectors,因此,当用户滚动通过我的索引页面中的div时,我实现了加载更多数据 我的div包含数据: <div class="container-fluid" id="post-data"> </div> <div class="ajax-load text-center" style="display:none"> <p><img src="http://demo.itsolutionstuff.com/plugin/loader.gif"
<div class="container-fluid" id="post-data">
</div>
<div class="ajax-load text-center" style="display:none">
<p><img src="http://demo.itsolutionstuff.com/plugin/loader.gif">Loading More post</p>
</div>
检查结果:
我还尝试:
var last_id = $(".row:last").attr("id");
但它不起作用
有什么建议吗
更新:
这实际上是一个语法错误,我的傻瓜!谢谢@SuperUser 试试看:
var last_id = $('#post-data:nth-last-child(1)').attr('id');
jquery脚本中有一些语法错误,应该是
var last_id = $('#post-data').children('.row').last().attr('id');
alert(last_id);
或
var last_id = $('#post-data .row:last-child').attr('id');
alert(last_id);
对最后一个孩子使用CSS选择器怎么样
var last_id = $('#post-data:last-child').prop('id');
我更喜欢使用道具,到目前为止还没有遇到任何问题,因为attr在过去给了我一些问题
您可能需要阅读以下内容:
.last().attr('id')
不起作用,它应该显示“5”@Dươngankhoa,根据您的php,您的结构需要如下:-。
类似的内容,而不是。
您使用的
var last_id = $('#post-data').children('.row').last().attr('id');
alert(last_id);
var last_id = $('#post-data .row:last-child').attr('id');
alert(last_id);
var last_id = $('#post-data:last-child').prop('id');