Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 1.40 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. JQuery - Get the DOM path of the clicked <a>
  2. <body>
  3. <div class="lol">
  4. <a class="rightArrow" href="javascriptVoid:(0);" title"Next image">
  5. </div>
  6. </body>
  7.        
  8. $(".rightArrow").click(function() {
  9. rightArrowParents = this.dom(); //.dom(); is the pseudo function ... it should show the whole
  10. alert(rightArrowParents);
  11. });
  12.        
  13. $(".rightArrow").click(function() {
  14.     var rightArrowParents = [];
  15.     $(this).parents().not('html').each(function() {
  16.         var entry = this.tagName.toLowerCase();
  17.         if (this.className) {
  18.             entry += "." + this.className.replace(/ /g, '.');
  19.         }
  20.         rightArrowParents.push(entry);
  21.     });
  22.     rightArrowParents.reverse();
  23.     alert(rightArrowParents.join(" "));
  24. });
  25.        
  26. $(".rightArrow").click(function() {
  27.     var rightArrowParents = [],
  28.         elm,
  29.         entry;
  30.  
  31.     for (elm = this.parentNode; elm; elm = elm.parentNode) {
  32.         entry = elm.tagName.toLowerCase();
  33.         if (entry === "html") {
  34.             break;
  35.         }
  36.         if (elm.className) {
  37.             entry += "." + elm.className.replace(/ /g, '.');
  38.         }
  39.         rightArrowParents.push(entry);
  40.     }
  41.     rightArrowParents.reverse();
  42.     alert(rightArrowParents.join(" "));
  43. });
  44.        
  45. $(".rightArrow")
  46.   .parents()
  47.   .map(function () {
  48.       var value = this.tagName.toLowerCase();
  49.       if (this.className) {
  50.           value += this.className.replace(' ', '.', 'g');
  51.       }
  52.   })
  53.   .get().join(", ");