
Untitled
By: a guest on
Jun 21st, 2012 | syntax:
None | size: 1.40 KB | hits: 10 | expires: Never
JQuery - Get the DOM path of the clicked <a>
<body>
<div class="lol">
<a class="rightArrow" href="javascriptVoid:(0);" title"Next image">
</div>
</body>
$(".rightArrow").click(function() {
rightArrowParents = this.dom(); //.dom(); is the pseudo function ... it should show the whole
alert(rightArrowParents);
});
$(".rightArrow").click(function() {
var rightArrowParents = [];
$(this).parents().not('html').each(function() {
var entry = this.tagName.toLowerCase();
if (this.className) {
entry += "." + this.className.replace(/ /g, '.');
}
rightArrowParents.push(entry);
});
rightArrowParents.reverse();
alert(rightArrowParents.join(" "));
});
$(".rightArrow").click(function() {
var rightArrowParents = [],
elm,
entry;
for (elm = this.parentNode; elm; elm = elm.parentNode) {
entry = elm.tagName.toLowerCase();
if (entry === "html") {
break;
}
if (elm.className) {
entry += "." + elm.className.replace(/ /g, '.');
}
rightArrowParents.push(entry);
}
rightArrowParents.reverse();
alert(rightArrowParents.join(" "));
});
$(".rightArrow")
.parents()
.map(function () {
var value = this.tagName.toLowerCase();
if (this.className) {
value += this.className.replace(' ', '.', 'g');
}
})
.get().join(", ");