element.nextElementSibling与element.previousElementSibling案例
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div> <ul> <li>123</li> <li>123</li> <li>123</li> <li id="four">第四个li</li> <li>123</li> <li>123</li> <li>123</li> <li>123</li> <li>123</li> <li>123</li> </ul> </div> <script> let li_4 = document.getElementById(‘four‘); li_4.previousElementSibling.style.backgroundColor = ‘pink‘; li_4.nextElementSibling.style.backgroundColor = ‘red‘; </script> </body> </html>
相关推荐
wikiwater 2020-10-27
IdeaElements 2020-08-19
Sophiego 2020-08-16
Kakoola 2020-08-01
Kakoola 2020-07-29
ELEMENTS爱乐冬雨 2020-07-18
ELEMENTS爱乐小超 2020-07-04
ELEMENTS爱乐小超 2020-07-04
Kakoola 2020-06-28
Feastaw 2020-06-18
Wmeng0 2020-06-14
ELEMENTS爱乐冬雨 2020-06-14
云之高水之远 2020-06-14
哈喽elements 2020-06-14
Feastaw 2020-06-11