Change Meta tag content dynamically in JavaScript

Add /Change Meta Tags Dynamically Using JavaScript

Is it possible to use JavaScript to change the meta-tags of the page?
Yes, it is definitely possible to use JavaScript to change the Meta tags of the page.

Change Meta tag content dynamically through JavaScript:

Let’s see the Example,
<!DOCTYPE html>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" id="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>dynamically add meta tag JavaScript</title>
    <script src="" async="async"></script>
            //update Meta Tag in Header

        var updateMetaTag = function (id) {
        var meta = document.getElementById(id);
        meta.setAttribute("content", "width=device-width, initial-scale=1.0");


        //document.querySelector('meta[name="viewport"]').setAttribute("content", "width=device-width, initial-scale=1.0");

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog -
My Books - Book 1 and Book 2 Powered by Blogger.