Dear W3Schools-Community,
There is something not working with my code right here. It should be mentioned that I am fairly new to using JavaScript.
Here is my HTML code (stripped down to the essential parts):
<!DOCTYPE html>
<html lang="de">
<head>
<script type="text/javascript">
function change_content(contentname)
{
if (document.getElementById(contentname).className = 'notactive')
{
document.getElementById('login').className = 'notactive';
document.getElementById('news').className = 'notactive';
document.getElementById('info').className = 'notactive';
document.getElementById('websites').className = 'notactive';
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
document.getElementById('content').innerHTML = this.responseText;
if (contentname == 'kontakt' || contentname == 'hilfe' || contentname == 'impressum')
{
document.getElementById('info').className = 'active';
}
else
{
document.getElementById(contentname).className = 'active';
}
}
};
xmlhttp.open('POST', contentname + 'page.php', true);
xmlhttp.send();
}
if (document.getElementById('info').className == 'active')
{
document.getElementById('dropdown-icon').src = "/ressource/images/nydoo-dropdown-icon-black.png";
}
else
{
document.getElementById('dropdown-icon').src = "/ressource/images/nydoo-dropdown-icon-yellow.png";
}
}
window.onload = change_content;
</script>
</head>
<header>
<ul id="mainnavigation">
<li id="mainlist" class="dropdown"><a id="info" class="notactive" onclick="change_content(this.id);">Information<img id="dropdown-icon"
style="width: 15px; height: 12px; float: right; margin-top: 7px; margin-right: 20px;" src="/ressource/images/nydoo-dropdown-icon-yellow.png"
id="dropdown_icon"></a></li>
</ul>
</header>
<body onload="change_content('login'); return false;">
<div id="content">
</div>
</body>
</html>
What I'm trying to do is changing the color from img (id="dropdown-icon") from yellow to black whenever a (id="info") has class "active". Also the other way around (class "notactive" -> change from black to yellow). Hopefully this describes it. It maybe a simple thing. But I'm getting frustrated with this issue. Let me know if I screwed it up myself :3
Thank you very much n advance.