plus-
plus-

Reputation: 46543

Jquery unrecognized expression

I'm using jquery v1.11.3 and I have an error when trying to evaluate a selector that has been escaped because of meta characters:

Uncaught Error: Syntax error, unrecognized expression: #foo\\/bar\\.buzz

But if I try to evaluate it in the console right away it works:

$('#foo\\/bar\\.buzz')
[<li id=​"foo/​bar.buzz" >​…​</li>​]

My simple question is why is the selector not working at eval time but works in the console?

Upvotes: 0

Views: 943

Answers (1)

Satpal
Satpal

Reputation: 133443

Your code works properly. Problem must be somewhere else.

$(function(){
  snippet.log('Yahooooooo: ' + $('#foo\\/bar\\.buzz').text())
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>
<div id='foo/bar.buzz'>test</div>

Upvotes: 1

Related Questions