Running into a spot of trouble and basically trying to create a variable which can be used as a selector. eg
$(\'a\').click(function(){
var selector = $(t
Modified version of @jcern`s fantastic code.
Features:
#elementIdelement.classNameelement with it's innerHtml appended (if any) and elements to shorten outputfunction dompath(element) {
var path = '',
i, innerText, tag, selector, classes;
for (i = 0; element && element.nodeType == 1; element = element.parentNode, i++) {
innerText = element.childNodes.length === 0 ? element.innerHTML : '';
tag = element.tagName.toLowerCase();
classes = element.className;
// Skip and tags
if (tag === "html" || tag === "body")
continue;
if (element.id !== '') {
// If element has an ID, use only the ID of the element
selector = '#' + element.id;
// To use this with jQuery, return a path once we have an ID
// as it's no need to look for more parents afterwards.
//return selector + ' ' + path;
} else if (classes.length > 0) {
// If element has classes, use the element tag with the class names appended
selector = tag + '.' + classes.replace(/ /g , ".");
} else {
// If element has neither, print tag with containing text appended (if any)
selector = tag + ((innerText.length > 0) ? ":contains('" + innerText + "')" : "");
}
path = ' ' + selector + path;
}
return path;
}