We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Ballyhoo


Posted By

fael on 09/09/07


Tagged

jquery breadcrumbs domtree


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

fael
francisre


element's absolute position in DOM Tree


Published in: JavaScript 


a function that returns the absolute position in DOM tree. jQuery based


  1. myId = function(me){ return me.id ? '#' + me.id : '' }
  2. myTag = function(me){ return me.tagName ? me.tagName.toLowerCase() : '' }
  3. myClass = function(me){ return me.className ? '.' + me.className.split(' ').join('.') : '' }
  4.  
  5. breadcrumbs = function(me){
  6. var path = [myTag(me) + myId(me) + myClass(me)];
  7. $(me).parents().each(function() {
  8. path[path.length] = myTag(this) + myId(this) + myClass(this);
  9. });
  10. return path.join(' < ');
  11. }
  12.  
  13. $('body').click( function(){
  14. alert( breadcrumbs(this) );
  15. });

Report this snippet 

You need to login to post a comment.