Reputation: 1833
i have html
<a href="#" data-ext="sql" rel="\dir\file.sql" id="file">file.sql</a>
And i want find this a#file
among others by rel
, so
$("#file[rel='\dir\file.sql']")
not works, because \
removing (why?)
var some_var = "/s/s/s/\a\a\a";
// undefined
some_var
// "/s/s/s/aaa"
So, how i can select item(items) by rel with \
in it?
And this is not all want to work
$("#file[rel='\\dir\\file.sql']")
$("#file[rel='/\dir/\file.sql']") // ^^
Example http://jsfiddle.net/fUNLV/1/ not works :(
Upvotes: 0
Views: 549
Reputation: 27765
You need to use double backslashed for this:
$("#file[rel='\\dir\\file.sql']")
This happens because just one \
slash will try to escape next symbol and double slashes will escape first slash.
UPDATE
Seems you need to use \\\\
:
$("#file[rel='\\\\dir\\\\file.sql']")
Upvotes: 1
Reputation: 27012
The backslash is an escape character. To escape the escape character, you can double it up:
Edit - In this case, the escaping needs to be double-escaped:
var $el = $('#file[rel="\\\\dir\\\\file.sql"]');
Upvotes: 3
Reputation: 95028
You need to escape both slashes, not just 1.
$("#file[rel='\\\\dir\\\\file.sql']") // that's 4 slashes in each case, 8 total
http://jsfiddle.net/Tentonaxe/fUNLV/2/
This is because First, this string is passed to jQuery, at which point it would become
"#file[rel='\\dir\\file.sql']"
then when it gets passed again internally to document.querySelectorAll()
, the slashes are correctly escaped for the css selector engine.
http://jsfiddle.net/Tentonaxe/fUNLV/4/
Upvotes: 1