Skip to content

Instantly share code, notes, and snippets.

@brianswisher
Created February 23, 2012 18:10
Show Gist options
  • Save brianswisher/1894172 to your computer and use it in GitHub Desktop.
Save brianswisher/1894172 to your computer and use it in GitHub Desktop.
Display data-attribute with corresponding classname
(function() {
var O,N,M,K,J,I,H,G,F,E,D,C,B,A,L;
M = "ref";
C = "number";
E = "." + M + ":before{";
E += "display:inline-block;";
E += "position:absolute;";
E += "padding:2px;";
E += "color:white;";
E += "background-color:black;";
E += "font-weight:bold;";
E += "}";
D = 1000;
A = "not found.";
O = document;
N = function(P) { return O.getElementsByClassName(P); };
K = K = O.createElement("style");
J = O.getElementsByTagName("head")[0];
I = N(M);
H = I.length;
for (F = 0; F < H; F++) {
G = I[F];
B = G.id || M + D;
G.id = B;
E += "#" + B + ':before{content:"' + G.getAttribute("data-" + C) + '";';
E += "z-index:" + D+++";";
E += "}";
}
if (H) {
K.appendChild(O.createTextNode(E));
J.appendChild(K);
console.log(I);
} else { console.log(M + " " + A); }
} ());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment