Changing value of 'content' prop in meta tag

I need to change the value of the “content” prop in meta tag… it looks like this is not easy… I looked it up… found a no. of SO threads about this… some respondents seemed horrified – ‘why on earth do you need to change the value of the ‘content’ prop in meta tag???’ well, I need to change it b/c in my website the language changes dynamically, from English to Spanish and vice-versa…

when I switch languages I can see clearly in Firebug how the content of the <title> element changes and also the value for the property “lang” in <html> tag (& other elements…) but the ‘content’ prop in <meta...> elem doesn’t budge (which I set up for it to change, just like for the other elements…)

$("meta#keywords").attr('content',metaKeywords);

etc…

(var metaKeywords of course evaluates to something diff, depending on what language is loaded…)

I even gave the meta tag an id, in the hopes of making it work this way, but it also doesn’t work…

is there any way at all to accomplish this? you can change practically every tag, properties, of tags, etc… dynamically, why not the value for the ‘content’ prop in meta tag? I find this weird…

thank you…

IIRC, meta tags are only parsed when you load the page. after that they simply are dead weight.

so meta tags differ from all other HTML elements in this respect??? seriously?

I don’t believe this…

thank you for your response…

meta tags are the HTML equivalent of MIME headers. makes a lot of sense to me, esp. since HTML was created long before the rise of SPAs.

Since they are there for the benefit of the browser (and spiders) not the user and are not actual page content, I don’t see this working or having the effect you imagine.
Probably something that would be best handled at the back-end.

this sucks…:frowning:

this is lousy for SEO… I bet you sites that change lang’s have found a way…

(and if I create these meta tags on the fly when the user chg’s lang’s? does this make sense?)

thank you…

problem is, I don’t have access to the lang var on the back-end… a while ago I tried to send the value of the ‘lang’ var to the back-end with AJAX, it didn’t work

oh brother… not good…

Works for me if you give it the correct ID.

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<meta id="metakeywords" name="description"  content="A general guide on the use of meta tags in html pages">
</head>

<body>

<script
      src="https://code.jquery.com/jquery-2.2.4.min.js"
      integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
      crossorigin="anonymous"></script>
      
      
<script>    
var metakeywords = "hello hello hello";
 $("#metakeywords").attr('content',metakeywords);     
</script>
</body>
</html>

TBH I would not trouble yourself with the keywords tag, it’s pretty much obsolete now. But description is worth having.

thank you… and thank you Paul – your solution worked – used diff id’s for the meta tags, that worked…

thank you very much!! :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.