zoukankan      html  css  js  c++  java
  • 查找兄弟元素

    示例

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    <!DOCTYPE html>
    <html>
        <head>
            <title>访问元素</title>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <style>
                .mycolor{
                    color:#fff;
                    
                }
                .steam{
                    color: red;
                }
            </style>
        </head>
        <body>
            <ul id="ul">
                <li id="ali">油条</li><li id="bli">包子</li><li id="cli">米饺</li><li id="dli"><a id="yufen">鱼粉</a></li>
            </ul>
            <script>
                // 查找父节点
                var tempel = document.getElementById("bli");
                tempel.className="steam";
                 
                var previousNode = tempel.previousSibling;
                previousNode.className="mycolor";
     
                var nextNode = tempel.nextSibling;
                nextNode.className="mycolor";
            </script>
        </body>
    </html>
  • 相关阅读:
    React.render和reactDom.render的区别
    CSS中position的4种定位详解
    React.js入门必须知道的那些事
    JS处理事件小技巧
    React.js深入学习详细解析
    React.js实现原生js拖拽效果及思考
    Linux ./configure && make && make install 编译安装和卸载
    Redis set集合结构及命令详解
    Redis数据过期策略
    Redis TTL命令
  • 原文地址:https://www.cnblogs.com/max-hou/p/11168122.html
Copyright © 2011-2022 走看看