Skip to content

Instantly share code, notes, and snippets.

@thatisuday
Last active May 11, 2017 07:46
Show Gist options
  • Save thatisuday/d5f0b8bde9c591753972737151f93bf8 to your computer and use it in GitHub Desktop.
Save thatisuday/d5f0b8bde9c591753972737151f93bf8 to your computer and use it in GitHub Desktop.
jQuery(document).click(function(event){
event.stopPropagation();
var elem = event.target;
function traverseUp(el){
var result = el.tagName + ':nth-child(' + ($(el).index() + 1) + ')',
pare = $(el).parent()[0];
if (pare.tagName !== undefined && pare.tagName !== 'BODY'){
result = [traverseUp(pare), result].join('>');
}
return result;
};
console.log('jQuery("body>' + traverseUp(elem) + '");');
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment