jQuery+css last-child實現選擇最后一個子元素操作示例
更新時間:2018年12月10日 10:21:01 作者:北方的刀郎
這篇文章主要介紹了jQuery+css last-child實現選擇最后一個子元素操作,結合實例形式分析了jQuery結合css進行頁面元素選擇與樣式修改相關操作技巧,需要的朋友可以參考下
本文實例講述了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>chabaoo.cn 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代碼運行工具:http://tools.jb51.net/code/HtmlJsRun測試,可得到如下運行效果:

更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery頁面元素操作技巧匯總》、《jQuery常見事件用法與技巧總結》、《jQuery常用插件及用法總結》、《jQuery擴展技巧總結》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
相關文章
jQuery EasyUI API 中文文檔 - NumberSpinner數值微調器使用介紹
jQuery EasyUI API 中文文檔 - NumberSpinner數值微調器使用,需要的朋友可以參考下。2011-10-10
Jquery+Ajax+PHP+MySQL實現分類列表管理(上)
本文將采用Jquery+Ajax+PHP+MySQL來實現一個客戶分類列表的管理,如何利用Ajax和Json技術讓用戶操作起來覺得更輕松,感興趣的小伙伴們可以參考一下2015-10-10

