Jquery escaping selector unrecognized expression: [data-route = search \\ / child]
I cannot find work for this problem.
In my SPA application I have different routes. # / search # / other # / search / child. I am parsing the hashtag and showing / hiding the element containing the data-route attribute.
When the path consists of one part # / search everything works fine. JQuery does $ ('[data-route = search]').
When I add the second part # / search / child, I go out of the selector at "search \ / child", but Jquery doesn't fire the selector with the following msg error:
Uncaught Error: Syntax error, unrecognized expression: [data-route=search\\/child] jquery.js:1850Sizzle.error jquery.js:1850tokenize jquery.js:2460select jquery.js:2847Sizzle jquery.js:1289jQuery.fn.extend.find jquery.js:5730jQuery.fn.jQuery.init jquery.js:197jQuery jquery.js:63allroutes MainView.js:21apply director.js:511_every director.js:308Router.invoke director.js:516updateAndInvoke director.js:474Router.dispatch director.js:482handler director.js:203onchange director.js:76
If I open my console and run the same selector it works fine.
var route = window.location.hash.slice(2);
route = route.replace('/','\\\\/');
var sections = $('[data-route]');
var selector = "[data-route=" + route + "]";
var section = $(selector);
if (section.length) {
sections.hide(250);
section.show(250);
}
+3
source to share