Question

Simple enough code:

$("meta[name=DCSext.Level]")

Error:

Error: Syntax error, unrecognized expression: [name=DCSext.Level]

I upgraded from 1.4.2 to 1.7.1 in Jquery. It obviously still works in 1.4.2.

Any thoughts?

Was it helpful?

Solution

The syntax should be [name="DCSext.Level"] as specified in the jQuery API. I recommend using single quotes for strings in JS so that you don't have to escape double-quotes, which I prefer to use for HTML:

$('meta[name="DCSext.Level"]')

Although you could continue to use double quotes:

$("meta[name=\"DCSext.Level\"]");

And you could swap the quote usage:

$("meta[name='DCSext.Level']");

This all of course assumes that the attribute itself is as follows:

<meta name="DCSext.Level" ... />

If DCSext is a JS object, you'll need to concatenate it into the string:

$('meta[name="' + DCSext.Level + '"]');

OTHER TIPS

You should add quotes if it is string:

$("meta[name='DCSext.Level']")

Or if it is variable:

$("meta[name='" + DCSext.Level + "']")

or if DCSext.Level is a variable:

$('meta[name="' + DCSext.Level + '"]');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top