Last active
August 29, 2015 14:06
-
-
Save dillinghamio/056dc42f9238ce0005ef to your computer and use it in GitHub Desktop.
Add Selectable Indentation for code output dynamically.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/