0

I ran into a cryptic error message from deep in the bowels of jQuery code.

Uncaught Error: Syntax error, unrecognized expression: <>

I'm sure the problem has nothing to do with jQuery itself. It's somewhere in my application, which is built in Backbone + Marionette.

I had to wade through hundreds of lines of code, but this test case demonstrates the problem in its simplest possible form. (You can go to the Mariontte.js web site and type this code in the JavaScript console.

var V = Marionette.CollectionView.extend({tagName: ''});
v = new V();

What am I doing wrong?

Patrick McElhaney
  • 57,901
  • 40
  • 134
  • 167
  • This begs the question: what were you trying to accomplish? – showdev Aug 05 '15 at 20:17
  • I'm getting spoiled by being able to find a solution to most of my problems within 5 minutes by just Googling the error message. Didn't work this time, so I figured I'd ask / answer my own question in hope of helping the next person. – Patrick McElhaney Aug 05 '15 at 20:22
  • That make sense. I was just curious about your purpose for specifying a blank "tagName". Maybe someone else has that same goal. Did you end up not using a blank string? – showdev Aug 05 '15 at 20:25
  • The reason was a very overworked coworker who hasn't had enough sleep. :) – Patrick McElhaney Aug 05 '15 at 20:29

1 Answers1

1

The problem is the empty tag name.

tagName: ''

There's some code in Marionette or Backbone that that basically does this:

jQuery('<' + tagName + '>')

So that an empty tagName causes jQuery to be called with <>, which is a meaningless expression. The tagName on CollectionView (or any View) is optional, but has to be an actual HTML tag. It can't be the emtpy string.

Patrick McElhaney
  • 57,901
  • 40
  • 134
  • 167