Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when used with jQuery 1.9 #416

Closed
pea opened this issue Jan 22, 2013 · 11 comments
Closed

Error when used with jQuery 1.9 #416

pea opened this issue Jan 22, 2013 · 11 comments
Labels

Comments

@pea
Copy link

pea commented Jan 22, 2013

When used with jQuery 1.9 I get this error:

"Uncaught Error: Syntax error, unrecognized expression: <div class="..."

Example: http://pastebin.com/kef1D8bH

@anlek
Copy link

anlek commented Jan 23, 2013

I have the same issue.

@anlek
Copy link

anlek commented Jan 23, 2013

So a little Googling around and I found this:
http://stage.jquery.com/upgrade-guide/1.9/#jquery-htmlstring-versus-jquery-selectorstring

Seems like it has nothing to do with Handlebars, but how jQuery parses template HTML in 1.9.

I found that URL from this issue: http://stackoverflow.com/questions/14347611/jquery-1-9-client-side-template-syntax-error-unrecognized-expression

Hope that helps

@jmorton
Copy link

jmorton commented Feb 1, 2013

Thanks for the stackoverflow link. After reading the discussion, I decided to work around this problem by trimming leading white space from the template's output.

I changed this...

$(this.template(this.model.attributes));

to this...

$(this.template(this.model.attributes).trim());

While it might be nice for Handlebars to trim things automatically, that seems like it could have some unintended consequences.

@anlek
Copy link

anlek commented Feb 1, 2013

I agree, I had to trim my template as well, however IE 9 didn't like the trim() command so I had to use the replace to make it work. (http://stackoverflow.com/questions/498970/how-do-i-trim-a-string-in-javascript)

@pkrakowiak
Copy link

Just ran into the same issue. Trimming the HTML text generated by Handlebars does the trick.

@wagenet
Copy link
Collaborator

wagenet commented Feb 13, 2013

It's worth considering whether Handlebars should trim its output to begin with.

@xmen4u
Copy link

xmen4u commented Feb 17, 2013

Thanks! came to the same conclusion and also blamed jquery :)
i don't think handlebars should do the trimming... it can be used across any text based format and maybe the space is intended.

@honi
Copy link

honi commented Mar 8, 2013

Having the same issue here. While @xmen4u has a point, maybe a global flag would do the trick.
Handlebars.autoTrim = True;

@mschatke
Copy link

Thank you for that solution.
A global flag would be nice - however should that be true or false by default?
Also an additional automatic detection would be nice to make handlebars work out-of-the box, especially for new developers. However that is not really a generic solution...

@kpdecker
Copy link
Collaborator

kpdecker commented Apr 7, 2013

Closing this issue so we can consolidate whitespace handling issues on #336

@kpdecker kpdecker closed this as completed Apr 7, 2013
@daverogers
Copy link

Update for anyone who also ran into this...

jQuery reverted their 1.9 HTML processing restrictions in v 1.10:

The biggest change you’re likely to see is that we’ve loosened up the criteria for HTML processing in $(), allowing leading spaces and newlines as we did before version 1.9

Simply upgraded to the latest version of jQuery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants