jQuery+css last-child實現(xiàn)選擇最后一個子元素操作示例
本文實例講述了jQuery+css last-child實現(xiàn)選擇最后一個子元素操作。分享給大家供大家參考,具體如下:
<!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.dbjr.com.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相關內(nèi)容感興趣的讀者可查看本站專題:《jQuery頁面元素操作技巧匯總》、《jQuery常見事件用法與技巧總結》、《jQuery常用插件及用法總結》、《jQuery擴展技巧總結》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
相關文章
jQuery實現(xiàn)自定義checkbox和radio樣式
這篇文章主要介紹了jQuery實現(xiàn)自定義checkbox和radio樣式的相關資料,需要的朋友可以參考下2015-07-07jQuery EasyUI API 中文文檔 - NumberSpinner數(shù)值微調(diào)器使用介紹
jQuery EasyUI API 中文文檔 - NumberSpinner數(shù)值微調(diào)器使用,需要的朋友可以參考下。2011-10-10Jquery+Ajax+PHP+MySQL實現(xiàn)分類列表管理(上)
本文將采用Jquery+Ajax+PHP+MySQL來實現(xiàn)一個客戶分類列表的管理,如何利用Ajax和Json技術讓用戶操作起來覺得更輕松,感興趣的小伙伴們可以參考一下2015-10-10jQuery自定義動畫函數(shù)實例詳解(附demo源碼)
這篇文章主要介紹了jQuery自定義動畫函數(shù)實現(xiàn)方法,形式實例分析了jQuery通過插件結合數(shù)學運算實現(xiàn)滑塊動畫運動的效果,并附完整demo源碼供讀者下載,需要的朋友可以參考下2015-12-12