
Untitled
By: a guest on
Aug 5th, 2012 | syntax:
None | size: 1.34 KB | hits: 8 | expires: Never
Can I accomplish this with CSS?
<a href="something">A</a>
<a href="something_else">B</a>
<a href="something">A</a>
<a href="...">C</a>
body
{
counter-reset:section;
}
a:before
{
counter-increment:section;
content:counter(section)". ";
}
1. A
2. B
3. A
4. C
1. A
2. B
1. A
3. C
a:before
{
content:attr(data-counter)". ";
}
var linkcounter = {};
var counter = 0;
$("a").each(function() {
if (!linkcounter.hasOwnProperty($(this).attr("href"))) {
counter++;
linkcounter[$(this).attr("href")] = counter;
}
$(this).attr("data-counter", linkcounter[$(this).attr("href")]);
});
var linkcounter = {};
var counter = 0;
var anchors = document.getElementsByTagName('a');
for(var i = 0; i < anchors.length; i++) {
if (!linkcounter.hasOwnProperty(anchors[i].getAttribute("href"))) {
counter++;
linkcounter[anchors[i].getAttribute("href")] = counter;
}
anchors[i].setAttribute("data-counter", linkcounter[anchors[i].getAttribute("href")]);
}
http://google.com/
http://google.com
google.com
google.com/
www.google.com
var counter = 0, cache = {};
$('a').each(function (i, a) {
a = $(a);
var href = a.attr('href');
var c = cache[href];
if (!c) {
counter++;
c = counter;
cache[href] = c;
}
a.text(c + '. ' + a.text());
});