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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

    	<title>My Awesome DOM Router</title>
  	<body class="home">
		<h1>jQuery DOM Router Example</h1>
		<button id="add">Add class</button>
		<div id="container">

		<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>

 *  jquery-dom-router - v1.0.0
 *  Fire JavaScript based on body classes. Based off the DOM router in the Sage WordPress Theme.
 *  http://jqueryboilerplate.com
 *  Made by Tor Morten Jensen
 *  Under MIT License
!function(a){a.fn.watch||a.fn.unwatch||(a.fn.watch=function(b,c){return this.each(function(){var d=this,e=d[b];a(d).data("watch_timer",setInterval(function(){d[b]!==e&&(c.call(d,b,e,d[b]),e=d[b])},100))})},a.fn.unwatch=function(){return this.each(function(){clearInterval(a(this).data("watch_timer"))})}),a.DOMRouter||(a.DOMRouter={router:function(b,c){var d=this;d.$el=a(b),d.el=b,d.$el.data("DOMRouter.router",d),d.element=d.$el.find(a.DOMRouter.defaults.element),d.element.addClass("dom-router-ready"),d.init=function(){d.routes=c,a(document).ready(d.load),d.executed=[],d.element.watch("className",function(b,c,e){var f=e.replace(/-/g,"_").split(/\s+/);a.each(f,function(a,b){d.routeExecuted(b)||(d.fire(b),d.executed.push(b))})})},d.routeExecuted=function(a){return d.executed.indexOf(a)>-1},d.classes=function(){return d.element.get(0).className.replace(/-/g,"_").split(/\s+/)},d.load=function(){d.fire("common"),a.each(d.classes(),function(a,b){d.fire(b),d.executed.push(b)})},d.fire=function(a,b){var c,e=d.routes;c=""!==a,c=c&&e[a],c=c&&"function"==typeof e[a],c&&e[a](b)},d.init()},defaults:{element:"body"}}),a.fn.router=function(b){return this.each(function(){new a.DOMRouter.router(this,b)})}}(jQuery);

var $el = $('#container');

  	common: function() {
	  	$el.append('I was loaded because I am common<br>');
	home: function() {
		$el.append('I was loaded because I am at home<br>');
	laters: function() {
		$el.append('I was not loaded on page load, but perhaps I am a late arrival<br>');

$('#add').on('click', function(e) {

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.


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