How to Get the first node of the current node near the front

使用: Node.prototype.previousSbling

Usage and Node.prototype.nextSbling same.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div id="id1">李雷</div><div id="id2">韩梅梅</div>
    <script>
        document.getElementById('id2').previousSibling === document.getElementById('id1'); // true
        document.getElementById('id2').previousSibling.firstChild.nodeValue; // 李雷
    </script>
</body>
</html>

 

Guess you like

Origin www.cnblogs.com/aisowe/p/11506116.html