0

I'm getting this:

Uncaught Error: Syntax error, unrecognized expression: [data-id=1|31|2]

So what I gather from this and my attempts to fix it is that you can't use any special characters in HTML attributes. So, does anyone know of a way I can separate numbers within an attribute and maintain the ability to manipulate with javascript?

I threw this together real quick to show the issue better than I can explain. http://jsfiddle.net/zacharynicoll/fbJYq/

2
  • Any reason why you chose not to enclose the expression in double quotes? Commented Feb 21, 2012 at 16:17
  • 1
    Reason? More like the absence of reason is why I chose to do that. Commented Feb 21, 2012 at 16:28

4 Answers 4

1

The problem is not with the | symbol but with your selector.

$('ul[data-id=' + id + ']').show();

Should be

$('ul[data-id="' + id + '"]').show();

Without the quotes any special characters will be picked up as part of the selector.

Sign up to request clarification or add additional context in comments.

1 Comment

Don't you hate when you work on a bug for an hour or so, and the solution turns out to be, "add this one little character." Thank you good sir, worked perfectly.
1

You forgot to add the double quotes

From:

$('ul[data-id=' + id + ']').show();

To:

$('ul[data-id="' + id + '"]').show();

http://jsfiddle.net/kgMGB/3/

1 Comment

Sorry Xander, you're absolutely correct, I did forget to add the double quotes, but Kokos answered first. Thanks though!
1

Try with "":

 $('ul[data-id="' + id + '"]').show();

EDIT: Wow, three people with the correct answer simultaneously. I won't delete mine though, but only because I think this is very funny :) ;) ;-) :) (Give the upvotes to the guy who was 1 min. faster, i.e the farthest down, I suggest)

7 Comments

To be fair, my answer works too and I was a minute quicker ;P
See my edit.... your immediately voiced worries make this even funnier, on this "free work for absolutely nothing" website - a great place for psychological studies :) ;) No offense, really, PLEASE.
Though mine works I've no idea whether it should work or not. But it does on my browser without the extra quotes.
You're a gentleman sir. The fact that three other people suggested it was the missing quotes leads me to believe they're more right than me but as I say, it works!
Meh, yours was one minute later than theirs, I wouldn't quite say simultaneously. :)
|
0

Just replace the | with a -

http://jsfiddle.net/kgMGB/2/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.