Changing Facebook meta tag Content Attribute using JQuery

Idan Shechter picture Idan Shechter · Aug 14, 2011 · Viewed 38.5k times · Source

I want to know how can I use JQuery in order to replace the content attribute of my Facebook meta tags.

I searched StackOverflow and what I've found was this example:

$("meta[property=og:title]").attr("content", title);
$("meta[property=og:url]").attr("content", url);

In my code I have the following meta tags:

<meta property="og:title" content="some content"/>
<meta property="og:url" content="some content"/>
<meta property="og:site_name" content="some content"/>

When I run the function that should change the content for the 'title' and 'url' variables, the change doesn't take place. The same values for the 'content' still remains the same.

I want to know how, if it's possible, to use JQuery to change the value of Facebook's meta tags.

Answer

Jinn picture Jinn · Jun 13, 2012

This is how it worked for me:

$('meta[name=og\\:url]').attr('content', newVideoUrl);

note the double backslash, without it Jquery will fail with an error.