Search code examples
jqueryasp.netwebmeta-tags

Why is my dynamic changing of my meta description tag not changing it?


Inspired by Stephen Ostermiller's answer to my question here: https://webmasters.stackexchange.com/questions/53306/is-the-programmatic-addition-of-keywords-and-descriptions-worthwhile/53307?noredirect=1#comment53439_53307, I found here: Is it possible to use javascript to change the meta-tags of the page? this snippet of code:

$('meta[name=description]').remove();
$('head').append('<meta name="description" content="Find and optionally acquire all current and past Hugo award winning books">');

Unfortunately, on adding this code to the appropriate place (where the Hugo awards are loaded into the page), when I run the new version of the site and choose "View Page Source", I still see the same old description:

<meta name="description" content="Find and optionally acquire all current and past book, movie, and music award winners, such as Pulitzers for books, Oscars/Academy Awards for movies, and Grammies for music, as well as many other awards" />

(and it is not at the end of all the meta tags, as I would expect it to be if my code worked).

What am I doing wrong or missing here?


Solution

  • If you just want to change the description it'd be more straight forward to do this

    $('meta[name="description"]').attr('content','new content');
    

    I hope that's what you're looking for.