Search code examples
jqueryjquery-selectorsmetadatasizzlefacebook-opengraph

jQuery 1.6.2 Upgrade causing problem with meta selector


This worked fine with 1.4.

var ogimagetag = $('meta[property=og:image]').attr('content');

gives me

Uncaught Syntax error, unrecognized expression: [property=og:image]

The error seems to be sizzle.

Sizzle.error = function( msg ) {
    throw "Syntax error, unrecognized expression: " + msg;
};
jquery-1.6.2.js:4057 Uncaught Syntax error, unrecognized expression: [property=og:image]

Anyone know how I can select the content of og:image meta without causing an error? Or is this a bug with sizzle?


Solution

  • Put the value in quotes. I think it's the : that's confusing sizzle. Quoting the value fixes this.

    var ogimagetag = $('meta[property="og:image"]').attr('content');
    

    Example: http://jsfiddle.net/n7zse/