当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery+css last-child实现选择最后一个子元素操作示例

jQuery+css last-child实现选择最后一个子元素操作示例

2019年01月08日  | 移动技术网IT编程  | 我要评论

本文实例讲述了jquery+css last-child实现选择最后一个子元素操作。分享给大家供大家参考,具体如下:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en"
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>www.jb51.net jquery选择器</title>
<style>
.red{color:#ff0000;}
</style>
</head>
<body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//$('div p:last').addclass("red"); //$('div p:last') 选择 最后一个p元素 并高亮显示得出结果如下:
$('div p:last-child').addclass("red");//$('div p:last-child') 将选择所有位于div最后一个p子元素,并高亮:
});
</script>
<div>
<p>paragraph</p>
<p>paragraph</p>
<p>paragraph</p>
</div>
<div>
<p>paragraph</p>
<p>paragraph</p>
<p>paragraph</p>
</div>
<div>
<p>paragraph</p>
<p>paragraph</p>
<p>paragraph<span>sssssssssss</span></p>
</div>
</body>
</html>

这里使用在线html/css/javascript代码运行工具:测试,可得到如下运行效果:

更多关于jquery相关内容感兴趣的读者可查看本站专题:《jquery页面元素操作技巧汇总》、《jquery常见事件用法与技巧总结》、《jquery常用插件及用法总结》、《jquery扩展技巧总结》及《jquery选择器用法总结

希望本文所述对大家jquery程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网