diff --git a/css-path.js b/css-path.js index 4b2b3c9..f2f339a 100644 --- a/css-path.js +++ b/css-path.js @@ -35,8 +35,14 @@ var trim = require('trim') , id = elm.getAttribute('id') if (id) { - list.unshift(tag + '#' + trim(id)) - return list + list.unshift( tag + '#' + trim(id) ) + var isUnique = rootNode.querySelectorAll(list.join('>')).length === 1 + if (isUnique){ + return list + } else { + list.shift() + selector.push('#' + trim(id)) + } } if (className) @@ -57,4 +63,4 @@ var trim = require('trim') module.exports = function (elm, rootNode) { return path(elm, rootNode, []).join(' > ') -} \ No newline at end of file +}