Uncaught exception: Syntax error, unrecognized expression jQuery
Asked Answered
X

2

11

I am having a few problems with jQuery 1.6, I am trying to select this object $('#' + id) where id looks like skill|3345015|7868, but console always give me a :

Error : uncaught exception: Syntax error, unrecognized expression: |3345015|7868

Thanks for your help

Xeres answered 8/10, 2011 at 9:24 Comment(1)
I wish this question were more clear, in whether id was actually "skill|123...etc.", or whether that was just the selector, and id ~may~ be "skill or "123" or etc.. Read both answers for a full understanding.Hangman
F
21

Try -

$("div[id='skill|3345015|7868']")

You'll have to replace 'div' with whatever element you're searching for. Or, to search all elements -

$("*[id='skill|3345015|7868']")

Demo - http://jsfiddle.net/dV7xM/

Frolicsome answered 8/10, 2011 at 9:28 Comment(0)
G
15

According to w3.org

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

So basically you have an invalid ID and that should be the reason for the parse error

Galluses answered 8/10, 2011 at 9:35 Comment(1)
so basically jQuery is stuck at HTML 4, since HTML 5 allows any character in an id :(Revoice

© 2022 - 2024 — McMap. All rights reserved.