jQuery——siblings()方法
生活随笔
收集整理的這篇文章主要介紹了
jQuery——siblings()方法
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
作用:選取除自己外所有同級(jí)元素,即對(duì)同級(jí)元素進(jìn)行反選
【例】改變同級(jí)元素的背景顏色,代碼效果
【代碼】
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>ul {list-style: none;}li {float: left;width: 50px;height: 50px;line-height: 50px;text-align: center;color: #fff;background-color: #424242;margin-left: 5px;border-radius: 5px;}.active {background-color: steelblue;}</style> </head> <body><ul><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li></ul> </body> <script src="./jquery.js"></script> <script>$('li').click(function () {$(this).removeClass('active')$(this).siblings().addClass('active')}) </script> </html>?
總結(jié)
以上是生活随笔為你收集整理的jQuery——siblings()方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: jQuery的next()、nextAl
- 下一篇: jQuery——parent(),par