Update the content attribute of the meta tag

2019-04-30 19:54发布

问题:

I have this:

<meta name="description" content="NEED_TO_UPDATE_THIS" />
<meta name="keywords" content="" />

and i need to update the content of meta tag that has the name="description" using jQuery. How can i use the selectors to choose that content atribute of that tag?

thanks

回答1:

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

Although doing this doesn't make much sense because web crawlers which use this tag usually don't support javascript.



回答2:

This will make sense when you are using phantom js and prerender the js pages for seo and proxy the bots to the pre-rendered pages instead to the live site.