Skip to content

Instantly share code, notes, and snippets.

@dillinghamio
Last active August 29, 2015 14:06
Show Gist options
  • Save dillinghamio/056dc42f9238ce0005ef to your computer and use it in GitHub Desktop.
Save dillinghamio/056dc42f9238ce0005ef to your computer and use it in GitHub Desktop.
Add Selectable Indentation for code output dynamically.
var indentElements = $('[class*="tab-"]');
$.each(indentElements, function (index) {
var indentAmount = parseInt(this.className.split('-')[1]);
var indentation = new Array(indentAmount + 1).join('    ');
this.innerHTML = indentation + this.innerHTML
});
<p class="tab-1">Hello World</p>
<p class="tab-2">Hello World</p>
<p class="tab-3">Hello World</p>
<p class="tab-4">Hello World</p>
@dillinghamio
Copy link
Author

This code adds however many tabs the class indicates, class-4 produces 4 tabs and then prepends that number of tabs into the element containing the class

Here is a demo http://jsfiddle.net/BrianDillingham/h642v964/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment