Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <p>Traverse up, down, left and right with:
  <br> <code>Node.parentNode</code> , 
  <code>.firstChild</code> , 
  <code>.lastChild</code> , 
  <code>.childNodes</code> ,  
  <code>.previousSibling</code> , 

<ul id="nav">
  <li><a href="/" id="home">MENU ITEM 1</a></li>
  <li><a href="/about" id="about">MENU ITEM 2</a></li>
  <li><a href="/contact" id="contact">MENU ITEM 3</a></li>

<input type="button" onclick="targetParent()" value="Target Parent Node <li> of Middle href"/>

<input type="button" onclick="prevNextSibling()" value="Target Next and Previous <li> of Middle"/>

<input type="button" onclick="firstChillin()" value="Target First Child of <ul>"/>

<input type="button" onclick="lastChillin()" value="Target Last Child of <ul>"/>

<input type="button" onclick="allNodes()" value="Target All childNodes of <ul>"/>

<input type="button" onclick="clearAll()" value="Clear All"/>


                body {
  background-color: #222;
  color: #999;
  padding: 2rem;
  font-family: arial;
p {
  line-height: 1.5rem;
a { 
  color: #fff; 
  text-decoration: none; 
  font-size: 1.3rem; 
ul {
  background-color: #444;
  margin: 2rem 0 1rem 0;
  li {
    padding: .5rem;
code {
  padding: 2px 4px;
  font-size: 90%;
  color: #c7254e;
  background-color: #f9f2f4;
  border-radius: 4px;
code, kbd, pre, samp {
  font-family: Menlo,Monaco,Consolas,"Courier New",monospace;

.active { background-color: pink };
.previous { background-color: lightblue; };
.next { background-color: orange };
.first { background-color: red };
.last { background-color: red };
.all { background-color: rebeccapurple };

input[type="button"] {
  font-size: 1rem;



                var item = document.getElementById("about");
function targetParent() {
  item.parentNode.setAttribute("class", "active");
function prevNextSibling() {
  item.parentNode.previousElementSibling.setAttribute("class", "previous");
  item.parentNode.nextElementSibling.setAttribute("class", "next");
function clearAll() {
  var x = document.getElementsByClassName('active');
  if(x.length != 0) {
  var y = document.getElementById("nav").getElementsByTagName("li")
  for (var i = 0; i < y.length; i++) {
    y[i].classList.remove('previous', 'next', 'first', 'last', 'all');
// -------------------------------------------
// firstChild returns #text for empty space node
// You can get rid of the space in the html or use firstElementChild
var list = document.getElementById("nav");
function firstChillin() {
function lastChillin() {

// -------------------------------------------
// childNodes has the same empty space consideration
// so just use children.
function allNodes() {
  if (list.hasChildNodes()) {
    var children = list.children;
    for (var i = 0; i < children.length; i++) {