zoukankan      html  css  js  c++  java
  • JavaScript 查找元素 查询父节点parentNode

    查询父节点parentNode

    示例

    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
    <!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{
                    text-decoration: initial;
                }
            </style>
        </head>
        <body>
            <ul id="ul">
                <li id="a">油条</li>
                <li id="b" class="steam">包子</li>
                <li id="c" class="steam">米饺</li>
                <li id="d" ><a id="yufen">鱼粉</a></li>
            </ul>
            <script>
                // 查找父节点
                var el = document.getElementById('yufen');
                el.parentNode.className="mycolor";
            </script>
        </body>
    </html>
  • 相关阅读:
    树上路径
    [HNOI2017]礼物
    Spoj 8372 Triple Sums
    [Swerc2014 C]Golf Bot
    【bzoj2194】快速傅立叶之二 FFT
    Linux下perl模块安装
    angularjs form表单验证
    Angularjs兼容IE
    input file限制上传文件类型
    angularjs判断页面数据是否渲染完成
  • 原文地址:https://www.cnblogs.com/lsyw/p/11168102.html
Copyright © 2011-2022 走看看