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.