//cache selection of the ul
var ul = document.querySelector('ul');
//What is the parentNode of the ul?
console.log(ul.parentNode.nodeName); //logs body
//What are the childNodes of the ul? (WARNING: line breaks are text nodes!)
console.log(ul.childNodes); //logs array containing all child nodes including text nodes
//What is the first child of the ul?
console.log(ul.firstChild.nodeName); //logs comment
//What is the last child of the ul?
console.log(ul.lastChild.nodeName); //logs text
//What is the nextSibling of the first li?
console.log(document.getElementById('A').nextSibling.nodeName); //logs text
//What is the previousSibling of the last li?
console.log(document.getElementById('B').previousSibling.nodeName); //logs text
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.