JSFiddle - React, Tailwind, and code Playground
by eTiger13
JavaScript
$.fn.path = function(options) {
var $this = $(this);
var path = ''; // beginning string of path is a /
var elements = $this.parents().reverse();
$.each(elements, function(i) {
/* set to blank */
var id = ( $this.attr('id') ? $this.attr('id') : '' );
var class = ( $this.attr('class') ? $this.attr('class') : '' );
var tag = ( $this.attr('tagName') ? $this.attr('tagName').toLowerCase() : '' );
var index = '';
/* if it has multiple direct sibilings, it has to have the index set */
if( $this.siblings(tag).filter(":not(#facebox)").length > 0) {
index = $this.parent().children(tag).index(this);
index = ":eq("+index+")";
}
/* form path */
path = path + ' ' + tag + index;
})
return path;
};