本文實例講述了jQuery使用siblings獲取某元素所有同輩(兄弟姐妹)元素用法。分享給大家供大家參考,具體如下:
siblings()屬于jQuery篩選類的API,用來查找某個元素的所有同輩元素(所有兄弟姐妹)。
<div id="contentHolder"> <input type="button" value="1" id="button1"></input> <input type="button" value="2" id="button2"></input> <input type="button" value="3" id="button3"></input></div>
假如需要實現如下功能:點擊某個按鈕的時候,該按鈕背景色變成#88b828,其他按鈕背景色變成#15b494。這個時候,siblings這個API很有用,也很簡單。
$(function(){ $("#contentHolder input[type='button']").click(function(){ $(this).css("background","#88b828"); $(this).siblings().css("background","#15b494"); });})更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery頁面元素操作技巧匯總》、《jquery選擇器用法總結》、《jQuery表單操作總結》、《jQuery常用插件及用法總結》、《jQuery表格(table)操作技巧匯總》、《jQuery擴展技巧總結》及《jQuery常見經典特效匯總》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答