Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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.


                <div class="container">
  <div class="button addBtn">Add Child Node</div>
  <div class="button removeBtn">Remove Child Node</div>
    <div class="button changeAttrBtn">Change Attribute Value</div>
<div class="parent" data-count="0">
  <div class="child"> Child </div>
  <div class="infoBoard">


                .container {
  margin: 10px;

.button {
    background: purple;
    color: white;
    cursor: pointer;
    display: inline-block;
    font-size: 20px;
    padding: 1.75rem 1rem;
    text-align: center;
    text-decoration: none;
  font-weight: bold;
  margin: 5px;

.button:hover {
  background: #AD1457;  

.parent {
  border: 1px solid #ccc;
  padding: 10px;

.child {
  background: #673AB7;
  color: #fff;
  padding: 10px;
  margin-top: 5px;

.infoBoard {
  padding: 10px;
  border: 1px solid #ccc;
  font-size: 20px;
  padding: 1.75rem 1rem;
  background: #f4f4f4;


                if(!("MutationObserver" in window)) {
  document.body.innerText = "Not supported by your browser";

/* Create mutation observer */
const config = {
  childList: true,
  attributes: true,
  characterData: true
const observer = new MutationObserver(handler);

/* Observe target */
const parent = document.querySelector(".parent");
observer.observe(parent, config);

/* Callback function when mutation happens */
function handler(mutationRecords, observer) {
  console.log("Handle mutation");
  mutationRecords.forEach((mutationRecord) => {
         const info = document.querySelector(".infoBoard");
      switch(mutationRecord.type) {
        case "childList":
info.innerText = "Mutation Observer handler: Child node added or removed";
        case "attributes":
          info.innerText = `Mutation Observer handler: Parent attribute modified: ${mutationRecord.attributeName} : ${}`;
          info.innerText = "";

/* Add child nodes when clicked on add child node button */

document.querySelector(".addBtn").addEventListener("click", () => {
console.log("Add child");
  const child = document.createElement("div");
child.className = "child";
  child.innerText = "Child ";

/* Remove child nodes when clicked on remove child node button */
document.querySelector(".removeBtn").addEventListener("click", () => {
console.log("Remove child");
  const child = parent.firstChild;

/* Change attribute value when clicked on change attribute button */
document.querySelector(".changeAttrBtn").addEventListener("click", () => {
console.log("Change attribute value");
  parent.setAttribute("data-count", parent.childNodes.length);