const app = document.getElementById(‘app‘); app.innerHTML = ` <h1>JavaScript DOM</h1> <ul id="list"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> `; const listItem = document.querySelector(‘#list li‘); // Any DOM Nodes console.log(listItem.nextSibling); console.log(listItem.previousSibling); // Any Element Nodes console.log(listItem.nextElementSibling); console.log(listItem.previousElementSibling);
原文地址:https://www.cnblogs.com/Answer1215/p/12596292.html
时间: 2024-10-13 09:27:34