$.nano = function(template, data) {
return template.replace(/\{([\w\.]*)\}/g, function (str, key) {
var keys = key.split("."), value = data[keys.shift()];
$.each(keys, function () { value = value[this]; });
return (value === null || value === undefined) ? "" : ($.isArray(value) ? value.join('') : value);
});
};
<script id="results-tmpl" type="text/html">
<p>Correct: {correct}</p>
<p>Wrong: {wrong}</p>
</div>
</script>
$("#container").html($.nano($("#results-tmpl"), {correct : "1"}));
<script src="//javascript/my.js" />
$(document).one('click', function(event) {
var i=100, arr = [], current = $(event.target);
while(i-- > 0 && current[0].nodeName.toLowerCase() !== 'body') {
arr.push(
(current.attr('id') && "#"+current.attr('id'))
|| (current.attr('class') && current[0].nodeName.toLowerCase() +"."+current.attr('class'))
|| (current[0].nodeName.toLowerCase() + ":eq(" + current.index() + ")"));
current = current.parent();
}
console.log(arr.reverse().join(' '));
});