diff --git a/css-path.js b/css-path.js index 4b2b3c9..40017e0 100644 --- a/css-path.js +++ b/css-path.js @@ -35,7 +35,8 @@ var trim = require('trim') , id = elm.getAttribute('id') if (id) { - list.unshift(tag + '#' + trim(id)) + var escapeSelector = function(selector) {return "".replace.call(selector,/(^[^_a-zA-Z\u00a0-\uffff]|[^-_a-zA-Z0-9\u00a0-\uffff])/g, "\\$1")}; + list.unshift(tag + '#' + escapeSelector(trim(id))) return list } @@ -57,4 +58,4 @@ var trim = require('trim') module.exports = function (elm, rootNode) { return path(elm, rootNode, []).join(' > ') -} \ No newline at end of file +}