JQuery – Get Unique path to element

var getUniquePath = function( node ) {

var parts = [];
if($(node).parent().children(node.tagName).length > 1) {
parts.push( node.tagName + ‘:eq(‘ + $(node).index() + ‘)’ );
}else {
parts.push( node.tagName );
}
$( node ).parents().each( function( index, element ) {
if($(element).parent().children(element.tagName).length > 1) {
parts.push( element.tagName + ‘:eq(‘ + $(element).parent().children(element.tagName).index(element) + ‘)’ );
} else {
parts.push( element.tagName );
}
});

return parts.join( ‘ > ‘, parts.reverse() );
}