cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation


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.

              <section class="demo">
	<button class="js-click">Click this button to change that  <code>div</code> &rarr;</button>

<div class="js-find changeable">
	&larr; This <code>div</code> will change when you click  that button 
	<output class="js-out output">This <code>output</code> will change when that &larr; <code>div</code> eventually changes</output>

<section class="summary">	
	<header class="summary__header">
	<p>Why are you doing this? </p>
	<p>How does this work?</p>
	<p>What is a good way to experience inception in a web page? </p>
	<p>Get the answers to all of these questions <a href="http://blog.frankmtaylor.com/2017/06/16/promising-a-mutation-using-mutationobserver-and-promises-together/">with this blog post</a>.</p>

<p>Or be lame, and just go to this <a href="https://gist.github.com/paceaux/8f8d5d1a57409c5b5f5f2519ceb8ac83">gist</a>, if you just want the code.</p>

              body {
	font-family: Helvetica, arial, sans-serif;
.summary__header {
	font-weight: 700;
	font-size: 1.5em;
.summary__header p {
	line-height: 1;
	margin: .5em 0;
.demo {
	display: flex;
	justify-content: space-around;
.output, .changeable {
	padding: .618em;
	font-size: 1.618em;
	border: 2px solid;

.output {
	border-color: #6688aa

.activated {
	font-weight: 700;
	background: rgba(180,220,230,.3);

.output {

const button = document.querySelector('.js-click');
const find = document.querySelector('.js-find');
const out = document.querySelector('.js-out');

button.addEventListener('click', (evt)=>{


/** AttrPromise
* @param {element} DOM element. required
* @param {attributeName} String. Optional. Attribute that is expected to change.
* @param {rejectTime} Int. Optional. Seconds (not ms) to wait before rejecting. 0 means there is no reject time.
* @returns {promise}
function attrPromise(element, attributeName,rejectTime = 0) {
	return new Promise((resolve,reject) => {
		let hasChanged = false;
		const observerConfig = {attributes: true,attributeOldValue:true};		
		const observer = new MutationObserver((mutations) => {
			mutations.forEach((mutation) => {
				// if attributeName is given and we have a matching change, disconnect and resolve
				if (attributeName && mutation.attributeName == attributeName) {
					hasChanged = true;
					resolve(element, element.getAttribute(attributeName));
				// no attributeName is given, but some attribute in general changed, disconnect and resolve
				if (!attributeName) {
					hasChanged = true;
		// Add a reject time if provided. Doesn't use recurrsion, but should it?
		if (rejectTime > 0) {
				if (!hasChanged) {
			},rejectTime * 100);
		if (attributeName) observerConfig.attributeFilter =[attributeName];
		observer.observe(element, observerConfig);
// use the attribute promise!
attrPromise(find,'class').then((element, attributeValue) => {
	out.innerText = 'I changed because the div got an attribute change';
}).catch((element)=> {
	out.innerText = 'The div never changed!';

Loading ..................