Q:

How to change image src when parent has "selected" class?

Im trying to change the image by looking at the parent class to see if it has "selected" in it. I have some code that adds the "selected" class to the "platform-selection" class.
<div class="platform-selection selected">
    <div style="margin: 5px;">
        <img src="xbox1.png" id="xbox" />
     </div>
</div>

    var xboxselected = document.getElementById("xbox").parentElement.parentElement.classList;
    if(xboxselected = "selected")
        {
           document.getElementById("xbox").src="xbox2.png";
        }
        else
        {
            document.getElementById("xbox").src="xbox1.png";
        }

I want to change the image to xbox2.png only when its parent parent has "selected" class. I instantly get the xbox2.png

A:

if(xboxselected = "selected")

That should be
if (xboxselected.contains("selected"))

= is assignment, not comparison. To compare things for equality you'd use === (or ==), but that makes no sense here because xboxselected is not a string, but a class list.
Just use its .contains method.

That said, if all you want to do is show a different picture depending on the class of a parent element (and the picture should change "live" whenever the class changes), you can just use CSS:

document.getElementById('demo').onclick = function () {
    document.querySelector('.platform-selection').classList.toggle('selected');
};
.platform-selection img.alternative {
    display: none;
}

.platform-selection.selected img {
    display: none;
}

.platform-selection.selected img.alternative {
    display: block;
}
<div class="platform-selection">
    <div style="margin: 5px;">
        <img src="https://i.imgur.com/1aCFcDj.jpg">
        <img src="https://i.imgur.com/rmPqh.gif" class="alternative">
     </div>
</div>

<button id="demo">Toggle selection</button>

There are two images. We use CSS to hide one of them initially (the one with class alternative). Whenever the parent element gains the selected class (here provided by a toggle button), it hides the (normally visible) contained image and displays the (normally hidden) alternative image.

