Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72473

Why do I keep getting "Uncaught TypeError: Cannot read property 'getAttribute'"? [duplicate]

$
0
0

I don't have any idea on why my code's not working. I looked on other similar questions, but didn't get a definitive answer. Any help is much appreciated. I have my script tag in the HTML head.

function changeFav() {
    var fav = document.getElementById("favicon");
    var title = document.getElementsByTagName("title");
    var title1 = "AnonSeeker | ";

    if ( window.location.href = "index.html" ) {
        var title2 = "Home";
    }

    if ( fav.getAttribute("href") === "img/favicon.ico" ) {
        fav.href = "img/anonfavicon.ico";
        title.innerHTML = "Google";
    } else {
        fav.getAttribute("href") = "img/favicon.ico";
        title.innerHTML = title1 += title2;
    }
}

function checkCommand() {
    if ( commandInput.value === "toggle-head" ) {
        changeFav();
    }
}
<head lang="en">
    <link type="image/x-icon" rel="shortcut icon" href="img/favicon.ico" id="favicon">
    <title>AnonSeeker | Home</title>
    <script src="changefavicon.js"></script>
</head>
<body>
    <button onclick="changeFav();">Change title and favicon</button>
</body>

Viewing all articles
Browse latest Browse all 72473

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>