Guest User

Untitled

a guest
Aug 5th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. Can I accomplish this with CSS?
  2. <a href="something">A</a>
  3. <a href="something_else">B</a>
  4. <a href="something">A</a>
  5. <a href="...">C</a>
  6.  
  7. body
  8. {
  9. counter-reset:section;
  10. }
  11.  
  12. a:before
  13. {
  14. counter-increment:section;
  15. content:counter(section)". ";
  16. }
  17.  
  18. 1. A
  19. 2. B
  20. 3. A
  21. 4. C
  22.  
  23. 1. A
  24. 2. B
  25. 1. A
  26. 3. C
  27.  
  28. a:before
  29. {
  30. content:attr(data-counter)". ";
  31. }​
  32.  
  33. var linkcounter = {};
  34. var counter = 0;
  35. $("a").each(function() {
  36. if (!linkcounter.hasOwnProperty($(this).attr("href"))) {
  37. counter++;
  38. linkcounter[$(this).attr("href")] = counter;
  39. }
  40. $(this).attr("data-counter", linkcounter[$(this).attr("href")]);
  41. });
  42.  
  43. var linkcounter = {};
  44. var counter = 0;
  45. var anchors = document.getElementsByTagName('a');
  46. for(var i = 0; i < anchors.length; i++) {
  47. if (!linkcounter.hasOwnProperty(anchors[i].getAttribute("href"))) {
  48. counter++;
  49. linkcounter[anchors[i].getAttribute("href")] = counter;
  50. }
  51. anchors[i].setAttribute("data-counter", linkcounter[anchors[i].getAttribute("href")]);
  52. }
  53.  
  54. http://google.com/
  55. http://google.com
  56. google.com
  57. google.com/
  58. www.google.com
  59.  
  60. var counter = 0, cache = {};
  61. $('a').each(function (i, a) {
  62. a = $(a);
  63. var href = a.attr('href');
  64. var c = cache[href];
  65. if (!c) {
  66. counter++;
  67. c = counter;
  68. cache[href] = c;
  69. }
  70. a.text(c + '. ' + a.text());
  71. });
Advertisement
Add Comment
Please, Sign In to add comment