查找 DOM 中具有特定类名的最后一个跨度
finding the last span in DOM with a particular classname
<div class="comments_container clearfix">
<hr />
<ul class="comment_struct">
<li class="commenter_pic">
<img src="images/im.jpg" alt="picture"/>
<span class="button blue square likes">9 Likes</span>
</li>
<li class="comment_data">
<ul class="post_info_options">
<li class="commenter_name">Abc</li>
<li class="comment"><p>hello how are you doing</p></li>
<li class="time">
<span class="comment_time">12 June 2012<>
<span class="time_elapsed">7 hours ago</span>
</li>
<li class="options">
<span><a href="#">Once More</a></span>
<span><a href="#">Comment</a></span>
<span><a href="#" class="comment_like">Like</a></span>
</li>
<li>
</li>
</ul>
</li>
<li class="delete_comment"><img src="images/Cancel.png" alt="delete_post"/></li>
</ul>
<br/>
<ul class="comment_struct">
<li class="commenter_pic">
<img src="images/im.jpg" alt="picture"/>
<span class="button blue square likes">9 Likes</span>
</li>
<li class="comment_data">
<ul class="post_info_options">
<li class="commenter_name">Abc</li>
<li class="comment"><p>hello how are you doing</p></li>
<li class="time">
<span class="comment_time">12 June 2012<>
<span class="time_elapsed">7 hours ago</span>
</li>
<li class="options">
<span><a href="#">Once More</a></span>
<span><a href="#">Comment</a></span>
<span><a href="#" class="comment_like">Like</a></span>
</li>
<li>
</li>
</ul>
</li>
<li class="delete_comment"><img src="images/Cancel.png" alt="delete_post"/></li>
</ul>
<br/>
<ul class="comment_struct">
<li class="commenter_pic">
<img src="images/im.jpg" alt="picture"/>
<span class="button blue square likes">9 Likes</span>
</li>
<li class="comment_data">
<ul class="post_info_options">
<li class="commenter_name">Abc</li>
<li class="comment"><p>hello how are you doing</p></li>
<li class="time">
<span class="comment_time">12 June 2012<>
<span class="time_elapsed">7 hours ago</span>
</li>
<li class="options">
<span><a href="#">Once More</a></span>
<span><a href="#">Comment</a></span>
<span><a href="#" class="comment_like">Like</a></span>
</li>
<li>
</li>
</ul>
</li>
<li class="delete_comment"><img src="images/Cancel.png" alt="delete_post"/></li>
</ul>
<br/>
我有如上所述的 html 结构.. 所以从 $('.comments_container'( 开始,我如何使用类"comment_time"遍历到 DOM 中的最后一个跨度。帮助将不胜感激。
使用 children(( 进行遍历是可能的。但我想知道有没有更简单的方法
您可以使用 :last 选择器:
var mySpan = $('.comments_container span.comment_time:last');
相关文章:
- 表追加而不附加最后一个元素
- 无法在Ionic select中预先选择最后一个选项
- 为什么画布形状只在3个画布中的最后一个画布上渲染
- Jquery append oly获取循环Rails中的最后一个elemen
- 如何创建更好的方式来维护基于我的代码访问的最后一个页面
- dataTables-如何自定义分页类型以显示最后一个页码后面的省略号,
- 多维关联数组的最后一个索引
- 无法获取vis.js最后一个或第一个选定的网络节点
- 循环以检查数组中的最后一个图像
- 从输入值中删除最后一个单词
- 尝试使用Javascript正则表达式来获取“&"分隔文本,无论它是否's是最后一个值
- 为什么这个正则表达式不't匹配最后一个字母数字字符
- 查找 DOM 中具有特定类名的最后一个跨度
- 当 DOM 更改时,使用最后一个选择器更新变量
- 第一个孩子最后一个孩子 Dom 遍历不起作用
- jQuery 在编辑 DOM 后获取最后一个元素
- 检查元素是否是DOM中类的最后一个
- 如何交换第一个和最后一个DOM元素
- Javascript:如何获得Dom树中的最后一个字符
- 在querySelector:如何获得第一个和最后一个元素?dom中使用的遍历顺序