-1

For my fiddle below, I am seeing the error

http://jsfiddle.net/d3qD4/23/

How to handle the decimal and spaces( right now using .split, join() - not sure if this is the right way) and avoid the unrecognized expression. any ideas?

$('label[title=' + $this.text().split(" ").join("") + ']').prev('input').prop('checked', false);
2
  • What's the error you're seeing? Commented Mar 26, 2014 at 21:58
  • When I select 14.5 or on test.com checkbox they are being added to the div below and when i click on the image they should be removed from the div - it is happening with the rest of the checkboxes but not with these two - Error: Syntax error, unrecognized expression: [title=14.5 ] ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js Line 3 Commented Mar 26, 2014 at 22:15

1 Answer 1

2

Try wrapping the attribute value in quotes:

$('label[title="' + $this.text().split(" ").join("") + '"]')

So you end up with [title="14.5"] instead of [title=14.5]

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

4 Comments

I tried that - the error updates to Error: Syntax error, unrecognized expression: [title="14.5 "], doesn't work.
Looks like you have a space at the end.. is that why you're doing the split/join? Try $this.text().replace(/ /g, '')
I don't have any extra space, regex does not work too: you can check on my fiddle - jsfiddle.net/d3qD4/23
It has a newline and a whole bunch of space. This fixes the selector ($.trim() and the quotes): $('label[title="' + $.trim($this.text()) + '"]').

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.