/ Published in: JavaScript
a function that returns the absolute position in DOM tree. jQuery based
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
myId = function(me){ return me.id ? '#' + me.id : '' } myTag = function(me){ return me.tagName ? me.tagName.toLowerCase() : '' } myClass = function(me){ return me.className ? '.' + me.className.split(' ').join('.') : '' } breadcrumbs = function(me){ var path = [myTag(me) + myId(me) + myClass(me)]; $(me).parents().each(function() { path[path.length] = myTag(this) + myId(this) + myClass(this); }); return path.join(' < '); } $('body').click( function(){ alert( breadcrumbs(this) ); });