搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
jQuery 教程
jQuery 遍历
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>jQuery siblings()遍历同级兄弟示例 - 基础教程(div.cn)</title> <head> <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("li").siblings(".bold").css("background-color", "lightgreen"); }); </script> <style> .bold { font-weight: bold; } </style> </head> <body> <ul> <li class="bold">项目1 </li> <li>项目2 </li> <li>项目3 </li> <li>项目4 </li> <li class="bold">项目5 </li> <li class="bold">项目6 </li> <li>项目7 </li> </ul> </body> </html>
运行结果